From: Robert Klemme Date: 2003-05-13T16:30:17+09:00 Subject: State Pattern Implementation Hi all, I'd like to hear what people think: is this a reasonable implementation of the state pattern? (Apart from the fact, that class Foo is quite useless. :-) The other question is, whether rededinition of a method should issue a warning in verbose mode (suppressed here by Kernel#no_warn()). BOND$ cat state.rb module Kernel def no_warn(&b) old = $-w begin $-w = false b.call ensure $-w = old end end end class Foo def initialize st1 end def st1 no_warn do def self.foo; 100; end def self.bar; 101; end end end def st2 no_warn do def self.foo; 200; end def self.bar; 201; end end end end f = Foo.new p f.foo p f.bar f.st1 p f.foo p f.bar f.st2 p f.foo p f.bar BOND$ ruby -w state.rb 100 101 100 101 200 201 BOND$ robert