From: mail@... Date: 2019-02-15T10:20:40+00:00 Subject: [ruby-core:91558] [Ruby trunk Feature#15574] Prohibit to pass a block on super() implicitly 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/ Unsubscribe: