On 19/10/05, eoghan <ruby / redry.net> wrote:
> Hello
> Im doing a simple test. I have 2 files:
> mouse.rb
> ---------
> my_string = 'blah'
>
> rabbit.rb
> ---------
> require 'foo'
>
> print my_string
>
> eoghanj$ /opt/local/bin/ruby bar.rb
> bar.rb:3: undefined local variable or method `my_string' for
> main:Object (NameError)
>
> Im simplified my example down to this; and I cant see what im doing
> wrong... hope its not too stupid.
> I read this part about irb restrictions, but im not sure it applies?
> http://www.rubycentral.com/book/irb.html
> Thanks
> Eoghan
>
>

Unlike in php or c require and load do not simply replace the
statement with the file, but are carefull not to introduce any local
variables. Try the following.

mouse.rb
---
module AnimalConstants
  MOUSE_NAME = "Mickey Mouse"
end

rabbit.rb
---s
require 'mouse'

p AnimalConstants::MOUSE_NAME

Constants and Globals are imported. (Note that you do not need to
structure your constants using a module, it was just to show this
effekt.)

regards,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/