ruby on rails - Location of a sound file used by gem -
i tinkering around gem ruby on rails, upon executable want play sound wave file, seem not work thought, ones gem installed... far have
cmd = ("afplay 'sound/activated.wav'") exec cmd with file located und lib/sound/activate.wav, within gem folder, if use gem can't find file... there particular location have store files? thanks
if run that, afplay looking @ sound/activated.wav current directory, not gem directory.
in ruby 2.x can find directory script located in __dir__. (with precautions taken):
require 'shellwords' file = file.join(__dir__, 'sound', 'activated.wav') escfile = shellwords.escape(file) cmd = "afplay #{escfile}" if need make compatible older rubies, file.dirname(file.realpath(__file__)) same thing __dir__.
note exec replace ruby process new afplay process, terminate ruby code. in cases rather want system.
Comments
Post a Comment