ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:69843] [Ruby trunk - Feature #11325] [Open] Block is passed to initializer implicitly even when I asked not to.
       [not found] <redmine.issue-11325.20150702130531@ruby-lang.org>
@ 2015-07-02 13:05 ` andrew.kozin
  2015-07-02 13:49 ` [ruby-core:69844] [Ruby trunk - Feature #11325] [Rejected] " ruby-core
  1 sibling, 0 replies; 2+ messages in thread
From: andrew.kozin @ 2015-07-02 13:05 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:69844] [Ruby trunk - Feature #11325] [Rejected] Block is passed to initializer implicitly even when I asked not to.
       [not found] <redmine.issue-11325.20150702130531@ruby-lang.org>
  2015-07-02 13:05 ` [ruby-core:69843] [Ruby trunk - Feature #11325] [Open] Block is passed to initializer implicitly even when I asked not to andrew.kozin
@ 2015-07-02 13:49 ` ruby-core
  1 sibling, 0 replies; 2+ messages in thread
From: ruby-core @ 2015-07-02 13:49 UTC (permalink / raw)
  To: ruby-core

Issue #11325 has been updated by Marc-Andre Lafortune.

Status changed from Open to Rejected

It may be surprising to you, but this is by design.

You have to explicitly pass an empty block when using `super`:

    super(&nil)

There's also no way to change this even if we wanted to because of incompatibilities.

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

* Author: Andrew Kozin
* Status: Rejected
* 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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-02 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11325.20150702130531@ruby-lang.org>
2015-07-02 13:05 ` [ruby-core:69843] [Ruby trunk - Feature #11325] [Open] Block is passed to initializer implicitly even when I asked not to andrew.kozin
2015-07-02 13:49 ` [ruby-core:69844] [Ruby trunk - Feature #11325] [Rejected] " ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).