From: Sacha Schlegel Date: 2003-05-16T12:02:18+09:00 Subject: Re: State Pattern Implementation (2nd try) This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_wasp.net.au-11305-1053054135-0001-2 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi Robert and all I am about to need a ruby state machine. Eg state handling code. Did look at the state pattern in "Desing Patterns, E. Gamma, R. Helm, R. Johnson, J. Vlissides, Addison-Weslay, 1995 Will try to do that with ruby. Do YOU or anyone else have links to "implemented" ruby state pattern code? Concrete I have about 7 states and more transitions. Did look at your solution. I think I would like to seperate the different states with their own classes as they might get a little bit bigger. Sacha On Tue, 2003-05-13 at 15:30, Robert Klemme wrote: > Hi all, >=20 > I'd like to hear what people think: is this a reasonable implementation o= f > 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()). >=20 > BOND$ cat state.rb >=20 > module Kernel > def no_warn(&b) > old =3D $-w > begin > $-w =3D false > b.call > ensure > $-w =3D old > end > end > end >=20 > class Foo > def initialize > st1 > end >=20 > def st1 > no_warn do > def self.foo; 100; end > def self.bar; 101; end > end > end >=20 > def st2 > no_warn do > def self.foo; 200; end > def self.bar; 201; end > end > end > end >=20 > f =3D Foo.new >=20 > p f.foo > p f.bar >=20 > f.st1 > p f.foo > p f.bar >=20 > f.st2 > p f.foo > p f.bar > BOND$ ruby -w state.rb > 100 > 101 > 100 > 101 > 200 > 201 > BOND$ >=20 > robert >=20 > >=20 --=_wasp.net.au-11305-1053054135-0001-2 Content-Type: application/pgp-signature; name="signature.asc" Content-Transfer-Encoding: 7bit Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQA+xFbKjTNlL0xFfy4RAjE0AKCeXY75vceWOoOib2Ue+XX78NNcAACfVOaI FCw8zQW5tGL7vsarT0e2dWY= =UIos -----END PGP SIGNATURE----- --=_wasp.net.au-11305-1053054135-0001-2--