Introspection on aliased methods?

F

Farhad Farzaneh

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

Robert Dober

Is there a way to determine what equivalent methods are, that is, what
has been aliased to what on an object or class?
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
 
F

Farhad Farzaneh

Thanks - that's quite helpful.

Robert said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top