R
Ryan Paul
I'm trying to find a way to arbitrarily alter the class of an instance at
runtime. The documentation didn't appear to have any clues.
Ultimately, I want to be able to do something like this:
class MyClass1
def fnc1
puts "fnc1 in class 1"
end
end
class MyClass2
def fnc1
puts "fnc1 in class 2"
end
end
a = MyClass1.new
a.fnc1
puts a.class
a.class = MyClass2
a.fnc2
puts a.class
Python lets you do it thusly: someinstance.__class__ = someclass
I figure that even if the solution turns out to be devoid of elegance, I
can toss it into a method of the 'Class' class to achieve what I want.
TIA
--SegPhault
runtime. The documentation didn't appear to have any clues.
Ultimately, I want to be able to do something like this:
class MyClass1
def fnc1
puts "fnc1 in class 1"
end
end
class MyClass2
def fnc1
puts "fnc1 in class 2"
end
end
a = MyClass1.new
a.fnc1
puts a.class
a.class = MyClass2
a.fnc2
puts a.class
Python lets you do it thusly: someinstance.__class__ = someclass
I figure that even if the solution turns out to be devoid of elegance, I
can toss it into a method of the 'Class' class to achieve what I want.
TIA
--SegPhault