Difference between remove_method and undef_method
You can remove a method in two easy ways. The drastic
See below 2 simple example -
Example 1 using undef_method
Example 2 using remove_method
removes all methods, including the inherited ones. The kinderModule#undef_method( )
removes the method from the receiver, but it leaves inherited methods alone.Module#remove_method( )
See below 2 simple example -
Example 1 using undef_method
resultclass 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
: undefined method
x' for # (NoMethodError)
Example 2 using remove_method
x from A classclass 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
Comments
Post a Comment