我正在研究Zed Shaw的“学习
Ruby艰苦之路”练习25
http://ruby.learncodethehardway.org/ex25.html
当我导航到保存ruby文件ex25.rb的目录并启动IRB时,我收到以下错误:
Larson-2:~ larson$cd Ruby Larson-2:Ruby larson$ls ex25.rb Larson-2:Ruby larson$irb ruby-1.9.2-p290 :001 > require 'ex25' LoadError: no such file to load -- ex25 from /Users/larson/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/larson/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from (irb):1 from /Users/larson/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>' ruby-1.9.2-p290 :002 >
似乎require命令在这里不起作用.有什么我想念的吗?
我也尝试按照建议要求’./25’并得到以下错误:
Larson-2:Ruby larson$irb ruby-1.9.2-p290 :001 > require './ex25' SyntaxError: /Users/larson/Ruby/ex25.rb:1: invalid multibyte char (US-ASCII) from /Users/larson/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/larson/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from (irb):1 from /Users/larson/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
解决方法
这是因为Ruby 1.9.2中的
the working directory is no longer in the Ruby path.这确实有效:
require './ex25'