In fact, you did not redefine the Point class, you opened it again. A small piece of code illustrating the difference:
class Point def foo end end class Point def bar end end
Point now has two methods: foo and bar . Therefore, the second definition of Point did not replace the previous definition, it was added to it. This is possible in ruby scripts, as well as in irb (this is also possible with classes from the standard library, and not just with your own).
You can also really override classes using remove_const to remove the previous class name binding first:
class Point def foo end end Object.send(:remove_const, :Point) class Point def bar end end Point.instance_methods(false)
sepp2k
source share