ruby – 要求命令在Snow Leopard上的bash irb中不起作用

前端之家收集整理的这篇文章主要介绍了ruby – 要求命令在Snow Leopard上的bash irb中不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在研究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'
原文链接:https://www.f2er.com/ruby/268864.html

猜你在找的Ruby相关文章