C
Chucky
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.
I've found that the problem has been addressed in ruby-1.8.0. See google for
the small thread and the small patch :
http://groups.google.be/groups?hl=f...m=3F373C1F.2020507%40path.berkeley.edu&rnum=2
The problem I've is that these strange things still happen now, when I am
using ruby-1.8.2 !
Definitely, I don't understand all this stuff :
- Is this a feature or a bug ?
- Has this been fixed or not ?
- Why is it still there when a patch made its way to the CVS repository ?
- Why isn't it in the documentation ?
Thank you for your kind attention and, by advance, for your help !
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.
I've found that the problem has been addressed in ruby-1.8.0. See google for
the small thread and the small patch :
http://groups.google.be/groups?hl=f...m=3F373C1F.2020507%40path.berkeley.edu&rnum=2
The problem I've is that these strange things still happen now, when I am
using ruby-1.8.2 !
Definitely, I don't understand all this stuff :
- Is this a feature or a bug ?
- Has this been fixed or not ?
- Why is it still there when a patch made its way to the CVS repository ?
- Why isn't it in the documentation ?
Thank you for your kind attention and, by advance, for your help !