开发者

File Loading in irb

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜