I have a Ruby method that should load a specified file when called:
def self.from_file(file_name, origin = nil)
MyFile.new(File.read(file_name), file_name.split('/').last, origin)
end
But, when I try and use MyFile.from_file(‘path/to/file’) in irb I get a “LoadError: no such file to load” message. Using Ruby 1.9.2p180 w/ RVM on Mac OS X.
Any thoughts?
The
file_nameyou’re loading needs to either be relative to your current path, or a full path.If you’re using a relative path, in irb you can check the output of
Dir.pwdto see whereFile.readis trying to load your relative path from.