Removing methods from an inherited class

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, if class A contains method "hello" and class B inherits from A, is
it possible to remove method "hello" in the definition of class B?
Maybe a workaround could be making "hello" method private in class B.

NOTE: I do know that I can override "hello" method (something as "def
hello; nil; end") but I don't want it.

Thanks for any suggestion.

--=20
I=C3=B1aki Baz Castillo
<[email protected]>
 
A

Adam Prescott

Hi, if class A contains method "hello" and class B inherits from A, is
it possible to remove method "hello" in the definition of class B?
Maybe a workaround could be making "hello" method private in class B.

NOTE: I do know that I can override "hello" method (something as "def
hello; nil; end") but I don't want it.

Are you looking to do this to make it use A#hello instead of B#hello ? If
so, you might consider using `super`. That aside, you can look at
Kernel#undef_method and Kernel#remove_method (the two have different
semantics).

http://ruby-doc.org/core/classes/Module.html#M000446
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top