Issue #12861 has been updated by bug hit.


Yukihiro Matsumoto wrote:
> I don't see the real-world problem except for a bit of complexity behind. If we distinguished lexical super and dynamic super, it would confuse more users than the current behavior, I think.
> 
> Matz.

```ruby
  def self.foo
    bar do
      super()
    end
  end
```

I wouldn't say it's a major practical problem, I just think that it's a flaw that you can't tell what this super is going call, as it depends on how bar is invoked.  If there were distinct dynamic and lexical supers, I'd definitely prefer those to avoid ambiguity, making the code clearer and more self documenting

----------------------------------------
Feature #12861: super in a block can be either lexically or dynamically scoped depending on how the block is invoked
https://bugs.ruby-lang.org/issues/12861#change-62199

* Author: bug hit
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Target version: 
----------------------------------------
```ruby
class Class1
  def self.foo
    'foo'
  end
  def self.method1
    'method1'
  end
end

class Class2 < Class1
  def self.foo
    bar do
      super()
    end
  end
  def self.bar(&block)
    a = block.()
    define_singleton_method :method1, &block
    b = send(:method1)
    c = block.()
    [a, b, c]
  end
end

p Class2.foo # ["foo", "method1", "foo"]
```

It doesn't seem like a good idea for a given language construct to be either lexically or dynamically scoped, depending on how its surrounding block is invoked (which is not visible at the point of definition).  I think it would be better if super were always lexically scoped, and a different keyword (dynamic_super) were always dynamically scoped



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>