From: Sacha Schlegel Date: 2003-05-16T11:59:15+09:00 Subject: Re: State Pattern Implementation 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-10654-1053053945-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 ------------------------------------------------ Sacha Schlegel ------------------------------------------------ 4 Warwick Str, 6102 St. James, Perth, Australia sacha@schlegel.li www.schlegel.li public key: www.schlegel.li/sacha.gpg ------------------------------------------------ --=_wasp.net.au-10654-1053053945-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+xFYJjTNlL0xFfy4RAnAMAJwI827oS1PzLtu/KDVm2qDzd87qnQCfThcF 41yQSSbHQnofCIF+hEhyna8= =Sx/1 -----END PGP SIGNATURE----- --=_wasp.net.au-10654-1053053945-0001-2--