Require command not working within bash irb on Snow Leopard

Andrew Lauer Barinov picture Andrew Lauer Barinov · Aug 29, 2011 · Viewed 9.2k times · Source

I am working on Zed Shaw's Learn Ruby the Hard Way Exercise 25

http://ruby.learncodethehardway.org/ex25.html

When I navigate to the directory that holds the ruby file ex25.rb and launch IRB, I get these errors:

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 > 

It seems that the require command isn't working here. Is there something I am missing?

I also tried require './25' as suggested and get these errors:

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>'

Answer

Mischa picture Mischa · Aug 29, 2011

This is because the working directory is no longer in the Ruby path in Ruby 1.9.2. This does work:

require './ex25'