You can remove a method in two ways. Cutting
Module
Deletes all methods, including those inherited. More kind
Module
removes a method from the receiver, but it leaves only inherited methods.
See below 2 simple examples -
Example 1 using undef_method
class A def x puts "x from A class" end end class B < A def x puts "x from B Class" end undef_method :x end obj = B.new obj.x
the result is main.rb: 15: in ': undefined method x' for # (NoMethodError)
Example 2 using remove_method
class A def x puts "x from A class" end end class B < A def x puts "x from B Class" end remove_method :x end obj = B.new obj.x
Result - $ ruby main.rb
x from class A
Rameshwar Vyevhare Dec 15 '15 at 10:41 2015-12-15 10:41
source share