I have a class Duck
with an initialize
method that yields to a block:
class Duck
def initialize()
if block_given?
yield(self)
end
end
end
and a class TalkingDuck
that greets the programmer when it is initialized.
class TalkingDuck < Duck
def initialize()
super()
puts 'I am a duck'
end
end
When I call the constructor TalkingDuck.new
with a block, I don't want this block to be executed. This:
TalkingDuck.new { puts 'Quack' }
should only print I am a duck
, but not Quack
. How can I prevent the block from being executed?