Wednesday, May 9, 2012

Ruby 1.9.2 load path update

I encountered an odd error when I changed the "load" statement to "require" in section 1.3.3 on page 19 of David Black's book The Well Grounded Rubyist.

As of Ruby 1.9.2, the current directory, ".", was removed from the load path for security reasons. The load path is stored in the global variable "$:", which you can display by running the command 'ruby -e puts $:'

The effect of this change means the step on page 19, changing load "loadee.rb" to require "load" will fail with an error:

'require': cannot load such file -- loadee (LoadError)

The solution is to either add the current directory, './loadee', or use require_relative 'loadee'. I hope this helps anyone else who puzzled over that error.

1 comment:

  1. Thank you for the post! I am working The Well Grounded Rubyist and was puzzled by this issue. This cleared it up in an instant.

    ReplyDelete

Note: Only a member of this blog may post a comment.