From: Robert Klemme Date: 2007-10-04T22:52:23+09:00 Subject: Re: File scope variable 2007/10/3, Martin Martinos : > 7stud -- wrote: > > Martin Martinos wrote: > >> A > >> variable that I can access in each function of each class but which is > >> private to my .rb file. > >> > >> Does anybody has a idea? > > > > 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 What is wrong with this solution? my_path *is* visible in the current file only as far as I can see. Btw, what are you trying to achieve? Kind regards robert