From: dblack@... Date: 2006-03-09T01:41:25+09:00 Subject: Re: Having a block executed in the context of an instance Hi -- On Thu, 9 Mar 2006, Mike Austin wrote: > rmagick@gmail.com wrote: >> dblack@wobblini.net wrote: >> >>> I have to say, I've been wondering for many years... is self.x = 1 >>> really *that* bad? It just seems like such a minor thing to me. I >>> certainly wouldn't want to see new punctuation introduced just to >>> avoid it. >> >> +1 > > It may be a minor syntax thing, but I think it creates unnecessary ambiguity. > If there is a method called caption=(), I expect it to use that. I don't > write 'self' anywhere else in Ruby, so it just seems odd. Plus is helps > reduce hard to debug locals creation by misspellings. You can look at it the other way around, though: you *always* specify a receiver explicitly in Ruby, except in the one case where the receiver is self and the syntax is such as to be unambiguously a method call. > class Button > attr :caption, true > > def initialize(*args, &block) > instance_eval &block > end > end > > button = Button.new do > var :x > caption = 'Click Me' > end > > There is already 'attr' for classes, why not 'local' or 'var' for methods? I'm not seeing the connection between the two halves of that sentence :-) I don't think the existence of the attr_* methods implies that Ruby should adopt a system of variable declaration. (At least, I don't see how one follows from the other.) But I'm not sure I'm understanding you correctly. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black