A
Adriano Mitre
Does any one know how to reset a class in Ruby? Subsequent class
definitions don't replace the original, but are tipically appended to
it.
The following example is typical.
#########################
class Song
def play
puts "playing..."
end
end
s = Song.new
class Song
def stop
puts "stopped."
end
end
s.play #=> "playing..."
s.stop #=> "stopped."
#########################
How can I make s.stop produce a NoMethodError, ie., how can I reset Song
class prior to redefining it?
Besides, I would like to know how to undefine Song class, so that
Song.new produce a NameError, i.e., behaving as if it were never
defined.
Thanks!
definitions don't replace the original, but are tipically appended to
it.
The following example is typical.
#########################
class Song
def play
puts "playing..."
end
end
s = Song.new
class Song
def stop
puts "stopped."
end
end
s.play #=> "playing..."
s.stop #=> "stopped."
#########################
How can I make s.stop produce a NoMethodError, ie., how can I reset Song
class prior to redefining it?
Besides, I would like to know how to undefine Song class, so that
Song.new produce a NameError, i.e., behaving as if it were never
defined.
Thanks!