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.
Farhad F. (Guest)
on 2007-07-30 19:17
Is there a way to determine what equivalent methods are, that is, what
has been aliased to what on an object or class?
Robert D. (Guest)
on 2007-07-30 19:37
(Received via mailing list)
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
Farhad F. (Guest)
on 2007-07-30 22:49
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>
>
This topic is locked and can not be replied to.