I have an object like this
class SomeObject
def initialize &block
# do something
end
end
class AnotherObject < SomeObject
def initalize &block
super
# do something with block
end
end
When super is called in AnotherObject, the block seems to be passed to SomeObject. Is this the right behaviour and is there away round it?
According to rubyspec this is the correct behaviour, even if you pass explicit arguments to super (i.e.
super('foo'))If you don’t want to pass that block, you could just pass a block that does nothing, although this isn’t quite the same thing (e.g. if the method changes its behaviour based on
block_given?)It appears that
is a way to pass no block at all to super, although I couldn’t find this in ruby spec.