From: Lionel Thiry Date: 2005-03-15T23:02:03+09:00 Subject: Re: Feature or bug ?? Chucky wrote: > Hi ! > > I came upon a strange behaviour of ruby when using a code block in the > constructor. Here is a minimalist version of program which shows that : > > ------8<--------------------8<--------------------8<--------------------8<-------------- > class C1 > def initialize( &code ) > code.call > end > end > > class C2 < C1 > def initialize( &block ) > super > # @c1 = C1.new > puts "I went here !" > end > end > > c2 = C2.new do puts "Damn! This went wrong !" end > ------8<--------------------8<--------------------8<--------------------8<-------------- > > Obviously, the program SHOULDN'T display "Damn! This went wrong !" ... but > actually it does ! > > The very interesting thing is that this happens ONLY with super ! In fact, > new and other methods are not subject to this hazardous processing. If you > comment the "super" line and uncomment the following one, you will see > that. > > Definitely, I don't understand all this stuff : > - Is this a feature or a bug ? It's a bug. (or a really surprising feature) When a see "super", I feel like seeing a method call, a special one, yes, but still a method call. Then I naturally expect it to behave like a method call, and a method call doesn't do any implicit block passing, nor argument passing, even when omitting parens. Regards, Lionel Thiry