From: Robert Klemme Date: 2007-10-04T23:19:56+09:00 Subject: Re: File scope variable 2007/10/4, Martin Martinos : > Robert Klemme wrote: > > 2007/10/3, Martin Martinos : > >> > >> 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 > > In fact, it only visible in the current file but it's not visible in the > exec_my_bin() function and I don't want to write: Right you are. I overlooked that one. You could work around that using a lambda: $ ruby < foo = 100 > bar = lambda { puts foo } > bar[] > XXX 100 > def exec_my_bin() > `#{Pathname.new(__FILE__).realpath.dirname + 'bin/mybin'}` > end > > Also I don't want to use a global variable, which I think is a bad idea > since I don't want to use it in another file. Reasonable. But still, what do you need that for? Kind regards robert