Forum: Ruby Introspection on aliased methods?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B92e77600ddf31da8b72c2637431d2cf?d=identicon&s=25 Farhad Farzaneh (clipper)
on 2007-07-30 17:17
Is there a way to determine what equivalent methods are, that is, what
has been aliased to what on an object or class?
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2007-07-30 17:37
(Received via mailing list)
On 7/30/07, Farhad Farzaneh <ff@onebeat.com> 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
B92e77600ddf31da8b72c2637431d2cf?d=identicon&s=25 Farhad Farzaneh (clipper)
on 2007-07-30 20:49
Thanks - that's quite helpful.

Robert Dober 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>
>
This topic is locked and can not be replied to.