Introspection on aliased methods?


#1

Is there a way to determine what equivalent methods are, that is, what
has been aliased to what on an object or class?


#2

On 7/30/07, Farhad F. removed_email_address@domain.invalid wrote:

Is there a way to determine what equivalent methods are, that is, what
has been aliased to what on an object or class?

Posted via http://www.ruby-forum.com/.

Hmm I do not know how to identify which name was used originally and
which was aliased but if that does not matter you can do

24/122 > irb
irb(main):001:0> class A
irb(main):002:1> def x; end
irb(main):003:1> def y; end
irb(main):004:1> alias_method :z, :x
irb(main):005:1> end
=> A
irb(main):006:0> A.instance_method(:x) == A.instance_method(:y)
=> false
irb(main):007:0> A.instance_method(:x) == A.instance_method(:z)
=> true
irb(main):008:0>

you could loop over all instance_methods of a class, or do the same
stuff with method for any object.

HTH
Robert


#3

Thanks - that’s quite helpful.

Robert D. wrote:

24/122 > irb
irb(main):001:0> class A
irb(main):002:1> def x; end
irb(main):003:1> def y; end
irb(main):004:1> alias_method :z, :x
irb(main):005:1> end
=> A
irb(main):006:0> A.instance_method(:x) == A.instance_method(:y)
=> false
irb(main):007:0> A.instance_method(:x) == A.instance_method(:z)
=> true
irb(main):008:0>