Tuesday, January 1, 2013

load or require files into irb



First, determine ruby's loadpath on your computer by doing...
irb(main):001:0> $:
=> ["/usr/local/lib/site_ruby/1.9.1", "/usr/local/lib/site_ruby/1.9.1/x86_64-linux", 
"/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.9.1", 
"/usr/lib/ruby/vendor_ruby/1.9.1/x86_64-linux", 
"/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.9.1", 
"/usr/lib/ruby/1.9.1/x86_64-linux"]

If the file/s you "require" is not in ruby's loadpath, you need to specify them...
irb(main):004:0> Dir.glob('/home/j/aa/*.rb')
=> ["/home/j/aa/mmbiz.rb", "/home/j/aa/a.rb"]
irb(main):005:0> require "/home/j/aa/mmbiz.rb"
This is a test
=> true

No comments:

Post a Comment