7stud said:
Yes. Don't do it. That's a horrible idea. If a method in your class
needs a value, pass the value as an argument.
I agree with you on this point, but in some circumstance it would be
interesting to have file scoped variables. There are at least one
built-in variable that is local to the current file and it's the
__FILE__ variable. In fact in my require function I would use a local
variable that tells me what is the current file folder path. I would
also use it to localize the path of the binary files that my script
uses. I don't think in that case its a bad idea since __FILE__ has also
a file scope.
example:
require 'pathname'
my_path = Pathname.new(__FILE__).realpath.dirname
require my_path +'mylib'
def exec_my_bin()
`#{my_path + 'bin/mybin'}`
end