From: "David A. Black" Date: 2008-11-01T21:26:39+09:00 Subject: Re: How to access to local variables in enclosing scopes? Hi -- On Sat, 1 Nov 2008, Yuh-Ruey Chen wrote: >> In the end, you'll find out what looks like a big problem now >> actually isn't. The most important usecase for your desired >> scoping rules would be nested functions, and Ruby doesn't >> have them. And for the other use cases, constants, class- >> and module instance variables suffice. OTOH, you can nest >> blocks as much as you like and scoping is what you expect. > > I recognize that access to nonlocal vars can be simulated with > instance variables. It does seem weird to allow two different > paradigms that interact with each other in a confusing - or at the > least non-trivial - matter (just look at my confusion). Everyone gets confused by something along the way in learning a language. It can't really be used as a one-to-one measure of what's wrong with the language. I think you're making this all much more difficult for yourself than it needs to be, perhaps by starting from the premise that it must be badly designed with no workable solutions. You may well end up concluding that -- not everyone is destined to love Ruby -- but I do think there's much more that you can let the language tell you before you give up on it. One concept to keep in mind is "self". Instance variables are pegged to self; their visibility rule is that if self is x, then @var belongs to x. There are no exceptions to that, and it doesn't interfere with or really have anything to do with local variables. > I guess my big beef with Ruby is that it is too complex and bloated > with features that often are inconsistent or lack symmetry with each > other. It's too "magical", making it hard to learn exactly how the > language works. From a language design perspective, Ruby really seems > like a mess to me, although with moments of brilliance. Most of the > time, when I'm metaprogramming, I'm guessing and looking at the > output, hoping I got so-and-so quirk correct. I'd be interested in seeing some of these examples. In my experience, a great deal of what people find confusing or opaque in Ruby turns out to be confusing because it is so simple, and because there are so few exceptions to the rules. I've always been impressed with the strictness with which Ruby applies a small number of underlying principles. It's possible that a bit of analysis of some examples could help you nail some of those. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!