From: ahoward Date: 2003-01-31T01:02:14+09:00 Subject: Re: Local variables & blocks On Thu, 30 Jan 2003, Martin DeMello wrote: > But method-level scoping still works as before, so I don't see the problem. module M SOME_INIT_LIST.each do |item| temp = M.method_a item M.method_b temp end # temp lives on in M's namespace !!!!!!! end include M eval 'some code which may or may not set local var temp' if defined temp # something very important, but will always run because module M writer # screwed up!!!!!!!! end > why would you want an instance variable to be scoped to a block? i said 'object'. you said '@object'. i figured you had made a typo. i meant 'object'. > Pretty much, yeah. But in Ruby, with everything contained in methods and > classes anyway, I tend not to bother so much about the global namespace. If > one had to distinguish by wa of keywords, I'd rather see a 'local' keyword > than an 'export'. this is _exactly_ the case with C. can anyone here back me up that writing static int x; _everywhere_ in library code, or more precisely _forgetting_ to do it, is a _major_ headache! just last week i was compiling some sources i did not write into a wrapper libary, that author of the library stupidly had created a method named 'alloc', NOT made it static, and NOT named it mypackage_alloc or some such - you should have seen the error linking into c++ code... automatically exported varables and contrary to the entire notion of OO programing - one of the tenants being _encapsulation_, which i think extends to more that just objects. just earlier this week there was a thread about people wrapping things properly in modules so importing libraries did not pollute their namespace. another thought i had was that automatically exporting every damn variable must be a huge strain on the GC as well - for now it will now a reference to every single object you create in a block will remain... how will they ever get cleaned up? -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================