From: Robert Klemme Date: 2009-06-12T23:18:41+09:00 Subject: Re: method= and block 2009/6/12 Christopher Dicely : > On Thu, Jun 11, 2009 at 2:55 AM, James > French wrote: >> I would really like to an associate a block in this way. Is there a way round this? > > I don't think so. It isn't parsed as a normal method call, its parsed > as a special construct with the = that is converted into a method call > in a way which doesn't support picking up a block. I don't really > think that using = this way would be a good idea even if you could. +1 If I see this foo.bar = x do something end I assume that "foo.bar" becomes the result of evaluating "x do ... end". And the Ruby interpreter does so, too. Joel is absolutely right about the ambiguity. Note also that this it is not possible to somehow make a block work with a "regular" assignment (i.e. a direct variable assignment): bar = x do something end Again, x will be called with the block and the result will be assigned to bar. It would be a very bad idea IMHO to introduce inconsistencies here. Please rather try to find a different solution. Note that you can always do def bar(&b) @block = b end And then foo.bar do something end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/