include - Accessing variables from included files in Ruby -


How do you access a variable, which is defined in a file?

  # inc rb foo = "bar"; # Main.rb puts' inc.rb 'on foo # nameError: `foo' method for the undefined local variable or the main object: Object  

You can not access a local outside of that location that was defined - in this case the file. If you want variables that exceed the boundaries of the file, then make them local but anything else. $ foo , foo and @foo will all work.

If you really like decoration on any symbol (because you do not like the way you read it), a common hack is to define it as just one method: Def foo () "bar" end .


Comments