A slight surprise:
class A
def foo x
yield if block_given?
end
end
class B < A
def foo x
super(x, &nil)
super(x) {}
end
end
B.new.foo(3) {puts “Executed block!”}
This code now causes the block to be executed.
$ ruby-1.7.3 change.rb
$ ruby-1.8.0 change.rb
Executed block!
If you use the commented super-call instead, neither case executes the
block.
I didn’t see this in the change docs.
It’s not a big problem for this code, since I know the block passed to
super should be empty,
But I can imagine it would be a problem when the block is in some variable:
def foo
bl = get_a_block_maybe()
super(x, &bl)
end
Since bl may be nil or not, you have strange behavior. If bl == nil,
then the wrong block is propagated to super.