It is not. You cannot "redefine" class in Ruby - if you open the class again (as
in bug2.rb file) and define some methods in it, they will be _added_ to the
existing class.
···
On Wed, 30 Jun 2004 17:00:04 -0500, DaZoner wrote:
Imagine you want to redefine a class at runtime. One way to do it is to load
a different class definition at runtime.So make two class definitions in separate files and a test script:
bug1.rb --------------------------------------------------------------------
----------class Bug
def method1
end
endbug2.rb --------------------------------------------------------------------
----------class Bug
def method2
end
endbugtest.rb -----------------------------------------------------------------
------------load "bug1.rb"
b = Bug.new
list = b.methods
list.each { |methodName| print " ",methodName }
print "\n"load "bug2.rb"
b = Bug.new
list = b.methods
list.each { |methodName| print " ",methodName }
print "\n"----------------------------------------------------------------------------
--Using Ruby 1.8.1 the second printed line shows Bug to respond to both
method1 and method2 even though bug2.rb does not define method1. Is this a
bug?
--
Marek Janukowicz