I have a Ruby method that should load a spe开发者_StackOverflow社区cified 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_name
you'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.pwd
to see where File.read
is trying to load your relative path from.
精彩评论