From: Martin Martinos Date: 2007-10-03T13:21:50+09:00 Subject: Re: File scope variable 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 -- Posted via http://www.ruby-forum.com/.