[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Introspection on aliased methods?

Farhad Farzaneh

7/30/2007 3:19:00 PM

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-....

2 Answers

Robert Dober

7/30/2007 3:36:00 PM

0

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-....
>
>
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

--
[...] as simple as possible, but no simpler.
-- Attributed to Albert Einstein

Farhad Farzaneh

7/30/2007 6:50:00 PM

0

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>
>
--
Posted via http://www.ruby-....