Issue #6712 has been updated by marcandre (Marc-Andre Lafortune).


Hi,

> I'd prefer to have an official non-hacking way of achieving the same with just Ruby. Something simpler like:
> 
> class A
>   def a
>     2
>   end
> end
> 
> class A
>   def a
>     super! * 3
>   end
> end
> 
> A.new.a == 6
> 
> This way we wouldn't need to polute A with a_with_feature and a_without_feature methods if we're not interested on them.

The `alias_method_chain` pattern is now obsolete with `Module#prepend`:

module Triple
  def a
    super * 3
  end
end

class A
  prepend Triple
end

A.new.a # => 6



----------------------------------------
Feature #6712: Introduce super! for calling old definition when reopening classes
https://bugs.ruby-lang.org/issues/6712#change-27893

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 2.0.0


ActiveSupport adds support for alias_method_chain which is a hack for being able to call the original method being overriden when reopening a class:

Extracted from documentation:

http://apidock.com/rails/ActiveSupport/CoreExtensions/Module/alias_method_chain

"Encapsulates the common pattern of:

  alias_method :foo_without_feature, :foo
  alias_method :foo, :foo_with_feature"

I'd prefer to have an official non-hacking way of achieving the same with just Ruby. Something simpler like:

class A
  def a
    2
  end
end

class A
  def a
    super! * 3
  end
end

A.new.a == 6

This way we wouldn't need to polute A with a_with_feature and a_without_feature methods if we're not interested on them.


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