Hello,
I was thinking of using Modules for state modeling:
whailer% cat state_test.rb
module StateA
def test
puts "A"
self.extend StateB
end
end
module StateB
def test
puts "B"
self.extend StateC
end
end
module StateC
def test
puts "C"
self.extend StateA
end
end
class Stateful
def initialize init_state
self.to_state init_state
end
def to_state state
self.extend state
end
end
a = Stateful.new StateA
1.upto 5 do a.test end
whailer%
whailer% ruby state_test.rb
A
B
C
C
C
whailer%
Is it possible to re-extend object - extend it with A, then with B, and then with A again, i.e how do I change my object's inheritance tree dynamically?
--Ed