Why can't I alias_method :remove_method ?

P

Pat Maddox

irb(main):001:0> class Foo
irb(main):002:1> alias_method :eek:ld_remove_method, :remove_method
irb(main):003:1> end
NameError: undefined method `remove_method' for class `Foo'
from (irb):2:in `alias_method'
from (irb):2

But you can call remove_method from within the class, so why can't you
alias it? What other methods can't you alias? Or rather, what are the
restrictions/conditions under which you must use alias_method?
 
N

nobu

Hi,

At Thu, 10 Aug 2006 15:46:40 +0900,
Pat Maddox wrote in [ruby-talk:207490]:
irb(main):001:0> class Foo
irb(main):002:1> alias_method :eek:ld_remove_method, :remove_method
irb(main):003:1> end
NameError: undefined method `remove_method' for class `Foo'
from (irb):2:in `alias_method'
from (irb):2

But you can call remove_method from within the class, so why can't you
alias it? What other methods can't you alias? Or rather, what are the
restrictions/conditions under which you must use alias_method?

You can call a singleton method named remove_method which is
inherited from the super class, Module, but you didn't define
an instance method named remove_method.

You can:

class Foo
class << self
alias_method :eek:ld_remove_method, :remove_method
end
end
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top