From: "David A. Black" Date: 2010-10-16T22:19:18+09:00 Subject: Re: Is it possible to find out if an identifier is a method alias? ---993115281-1290907446-1287235154=:15824 Content-Type: MULTIPART/MIXED; BOUNDARY="-993115281-1290907446-1287235154=:15824" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---993115281-1290907446-1287235154=:15824 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Fri, 15 Oct 2010, Robert Klemme wrote: > On Fri, Oct 15, 2010 at 1:03 PM, Ammar Ali wrote: >> On Fri, Oct 15, 2010 at 2:17 AM, Daniel Berger wrote: >>> class Foo >>> �def alpha; end >>> �def beta; end >>> �alias gamma alpha >>> end >>> >>> Foo.instance_method(:alpha) == Foo.instance_method(:beta) # => false >>> Foo.instance_method(:alpha) == Foo.instance_method(:gamma) # => true >> >> Thanks Daniel. That's helpful. > > But which of the two is the alias? I could be wrong, and haven't dug into the code, but I've always had the impression that (by design) there's no difference between different ways to refer to a method. It's not that the alias is a kind of nickname for the "real" name; it *is* (one of) the real name(s). In 1.9.2, anyway, #instance_methods seems to list methods in the order they were created/aliased, though I don't know whether this is guaranteed: ruby-1.9.2-p0 > class C; def x; end; alias a x; def b; end; def d; end; alias c d; def f; end; def e; end; end => nil ruby-1.9.2-p0 > C.instance_methods => [:x, :a, :b, :d, :c, :f, :e, ... ] David -- David A. Black, Senior Developer, Cyrus Innovation Inc. The Ruby training with Black/Brown/McAnally Compleat Stay tuned for next event! Rubyist http://www.compleatrubyist.com ---993115281-1290907446-1287235154=:15824-- ---993115281-1290907446-1287235154=:15824--