From: Tom Cloyd Date: 2009-05-05T23:03:19+09:00 Subject: Re: problem accessing variables in module Robert Klemme wrote: > 2009/5/4 Tom Cloyd : > >> I keep getting blocked trying to do a very simple thing - I want to >> "include" - in the sense of causing a mere insertion of text - some >> variables and methods, residing in an external file, in my main code. I just >> want my main to read a file and insert what's in it into the code stream and >> then forget where it came from. Apparently this isn't possible in any way, >> sadly. >> > > That sounds as if you wanted to do > > class SN > eval(File.read("utils.rb")) # utils.rb contains method definitions etc. > end > > >> So, trying to play the game according to the rules, I find that a mere >> "require {filename}", then an "include {module name in that file}" doesn't >> do it, because the namespaces aren't merged, as I would have expected. (An >> include that doesn't include? Huh?) >> > > >> I realize a real Ruby programmer would start creating classes everywhere and >> > > You do have classes already. :-) > > >> then it would all work (I guess). I'm trying very hard to keep it simple, >> because the concept is simple. I don't need/want a class. Just the >> variable, which is initialized in the module. Simple idea - not simple to do >> - or at least I haven't discovered how to do it. >> > > >> Can someone give me the "missing piece" or suggest what I need to do to get >> this working? >> > > There's a sample attached which allows do extend individual instances > as well as include in classes. > > Kind regards > > robert > > > Robert, this is exactly what I was looking for. I'm a bit stunned, after so many failure to even communicate to others what I was trying to do. It's so straightforward. You got it solved right away. Thanks! This is very helpful to be, in my modest efforts to make a tool from which I will get a lot use! Thanks for your time and help. Tom -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~