ruby - Single quote string interpolation to access a file in linux -
how make parameter
file
of methodsound
become file name of .fifo >extension using single quotes? i've searched , down, , tried many different >approaches, think need new set of eyes on one.def sound(file) @cli.stream_audio('audio\file.fifo') end
alright got working, might not correct way seemed trick. first thing, there may have been white space interfering file parameter. used file.join option saw posted here few different people.
i used bit of each of answers really, , how came out:
def sound(file) file = file.strip file = file.join('audio/',"#{file}.fifo") @cli.stream_audio(file) if file.exist? file end
works charm! :d
ruby interpolation requires use double quotes.
is there reason need use single quotes?
def sound(file) @cli.stream_audio("audio/#{file}.fifo") end
as charles caldwell stated in comment, best way cross-platform file paths work correctly use file.join
. using that, method this:
def sound(file) @cli.stream_audio(file.join("audio", "#{file}.fifo")) end
Comments
Post a Comment