From: Robert Klemme Date: 2009-05-04T20:14:23+09:00 Subject: Re: problem accessing variables in module --0016e6d27ed182188504691443ca Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 j= ust > 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 =A0"include {module name in that file}" doe= sn't > do it, because the namespaces aren't merged, as I would have expected. (A= n > 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. =A0I 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 g= et > this working? There's a sample attached which allows do extend individual instances as well as include in classes. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --0016e6d27ed182188504691443ca Content-Type: application/octet-stream; name="sn.rb" Content-Disposition: attachment; filename="sn.rb" Content-Transfer-Encoding: base64 X-Attachment-Id: f_fub2m34f0 CnJlcXVpcmUgJ3V0aWxzJwoKY2xhc3MgU04KICBkZWYgaW5pdGlhbGl6ZQogICAgZXh0ZW5kIFV0 aWxzCiAgZW5kCmVuZAoKY2xhc3MgU04yCiAgaW5jbHVkZSBVdGlscwogICMgd2l0aG91dCBpbml0 aWFsaXplCmVuZAoKY2xhc3MgU04zCiAgaW5jbHVkZSBVdGlscwoKICBkZWYgaW5pdGlhbGl6ZQog ICAgc3VwZXIKICAgIHB1dHMgImluaXQgbXVzdCBjYWxsIHN1cGVyISIKICBlbmQKZW5kCgpbU04s IFNOMiwgU04zXS5lYWNoIHt8Y2x8IGNsLm5ldy5zaG93X21lbnV9Cgo= --0016e6d27ed182188504691443ca Content-Type: application/octet-stream; name="utils.rb" Content-Disposition: attachment; filename="utils.rb" Content-Transfer-Encoding: base64 X-Attachment-Id: f_fub2mayo1 bW9kdWxlIFV0aWxzCiAgZGVmIHNlbGYuZXh0ZW5kZWQob2JqKQogICAgc2V0X3VwKG9iaikKICBl bmQKCiAgZGVmIGluaXRpYWxpemUoKmEsJmIpCiAgICBzdXBlcgogICAgVXRpbHMuc2V0X3VwKHNl bGYpCiAgZW5kCgogIGF0dHJfYWNjZXNzb3IgOm1lbnUKCiAgZGVmIHNob3dfbWVudQogICAgcCBz ZWxmLCBzZWxmLm1lbnUKICBlbmQKCnByaXZhdGUKICBkZWYgc2VsZi5zZXRfdXAob2JqKQogICAg b2JqLm1lbnUgPSB7OnRlc3QgPT4gOmRhdGF9CiAgZW5kCmVuZAo= --0016e6d27ed182188504691443ca--