From: mail@stefanschuessler.de
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91558] [Ruby trunk Feature#15574] Prohibit to pass a block on super() implicitly
Date: Fri, 15 Feb 2019 10:20:40 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-76821.20190215102038.ddb2ec14879fbd77@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15574.20190130071217@ruby-lang.org
Issue #15574 has been updated by sos4nt (Stefan Schüßler).
I prefer the current behavior. Passing along a block is much more common than removing a block.
Let's say I have a class which yields `self` during initialization:
```ruby
class A
def initialize(foo)
# ...
yield self if block_given?
end
end
```
I can easily subclass the above and add an extra argument via:
```ruby
class B < A
def initialize(foo, bar = nil)
# ...
super(foo)
end
end
```
I don't even have to know whether `A` takes a block or not, Ruby takes care of it.
With the proposed change however, it becomes my responsibility. Almost every time I use `super(...)` I have to remember passing the block. The above code would become:
```ruby
class B < A
def initialize(foo, bar = nil, &block)
# ...
super(foo, &block)
end
end
```
Adding an explicit `&block` (and therefore creating a `Proc` object) for the sake of passing it along is something I'd like to avoid.
---
BTW, if you really have to remove all arguments including the block argument, it's merely:
```ruby
super(&nil)
```
That looks just fine to me.
----------------------------------------
Feature #15574: Prohibit to pass a block on super() implicitly
https://bugs.ruby-lang.org/issues/15574#change-76821
* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
As described in [Feature #15554], `super()` (not `super`) pass the given block.
```
class C
def foo
p block_given?
end
end
class C1 < C
def foo
super #=> true
super() #=> true
end
end
C1.new.foo{}
```
`super` (without parameters) passes all passed parameters so it is no surprise to pass given block.
However, `super()` (with parameters. In this case, it passes 0 parameters) also pass given block implicitly.
I'm not sure who use this behavior, but I think it is simple to prohibit such implicit block passing.
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2019-02-15 10:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15574.20190130071217@ruby-lang.org>
2019-01-30 7:12 ` [ruby-core:91332] [Ruby trunk Feature#15574] Prohibit to pass a block on super() implicitly ko1
2019-01-30 10:12 ` [ruby-core:91335] " Webhostingonedollar102
2019-01-30 10:17 ` [ruby-core:91336] " Webhostingonedollar102
2019-01-30 12:12 ` [ruby-core:91338] " eregontp
2019-02-04 18:25 ` [ruby-core:91394] " ruby-core
2019-02-05 2:02 ` [ruby-core:91402] " ko1
2019-02-05 3:27 ` [ruby-core:91403] " duerst
2019-02-05 4:42 ` [ruby-core:91404] " sawadatsuyoshi
2019-02-15 10:20 ` mail [this message]
2019-02-15 10:48 ` [ruby-core:91562] " sawadatsuyoshi
2019-02-15 11:02 ` [ruby-core:91563] " mail
2019-02-15 11:10 ` [ruby-core:91564] " sawadatsuyoshi
2019-02-15 11:42 ` [ruby-core:91566] " eregontp
2019-02-15 11:46 ` [ruby-core:91567] " mail
2019-10-21 8:14 ` [ruby-core:95451] [Ruby master " ko1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-76821.20190215102038.ddb2ec14879fbd77@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).