Chan S. in ruby-talk[284135] stumbled over the different scope of
alias and alias_method. See his example a little changed:
puts RUBY_VERSION #=> 1.8.6
class T
def self.redefine
p self
alias_method :bar_alm, :foo
alias bar_a foo
end
def foo ; puts “T’s foo” ; end
end
class S < T
def foo ; puts “S’s foo” ; end
redefine
end
s = S.new #=> S
s.bar_alm #=> S’s foo
s.bar_a #=> T’s foo
p S.instance_methods.grep(/foo|bar/) #=> [“foo”, “bar_a”, “bar_alm”]
p T.instance_methods.grep(/foo|bar/) #=> [“foo”, “bar_a”]
END
So:
alias_method results in an instance method bar_alm in S.
alias results in an instance method bar_a in T (and so in S).
I would like to repeat his question to straighten it out:
Is this difference between alias and alias_method a bug or a feature?
Thanks
Dirk