[ruby-core:69843] [Ruby trunk - Feature #11325] [Open] Block is passed to initializer implicitly even when I asked not to.

From: andrew.kozin@...
Date: 2015-07-02 13:05:32 UTC
List: ruby-core #69843
Issue #11325 has been reported by Andrew Kozin.

----------------------------------------
Feature #11325: Block is passed to initializer implicitly even when I asked not to.
https://bugs.ruby-lang.org/issues/11325

* Author: Andrew Kozin
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This works as expected:

~~~ruby
class Foo
  attr_reader :block

  def initialize(&block)
    @block = block
  end
end

foo = Foo.new { :foo }
foo.block.nil?
# => false
~~~

But then I'm trying to stop passing a block to the superclass' initializer and cannot do this:

~~~ruby
class Bar < Foo
  def initialize(&block)
    block = nil # added it, however this shouldn't be necessary
    yield       # nor this one
    super()     # explicitly asked not to pass the block
  end
end

bar = Bar.new { :foo }
bar.block.nil?
# => false (expected true)
~~~

Adding an empty block is not the solution, because what is really needed is **stop passing a block**.



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next