From: Pete Elmore Date: 2004-11-04T19:14:26+09:00 Subject: Re: Hashes and Blocks (Syntactical/Feature question) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thanks for all of the helpful responses! "Gavin Sinclair" wrote: | states = Hash.new( lambda { puts "fallback" } ).update( That's interesting; it had not occurred to me to use the default hash value like that. "Jim Haungs" wrote: | What you're trying to do is an example of the State pattern, which is | often implemented with sensibly-named states (as opposed to the | numbers in the example here). Yeah, actually, I was simplifying it a little; I used names for the states. | With the hash table scheme, the cohesion is poor because the current | machine state is separated from the operations on that state. Very good point. But writing a class to handle a state machine for a program that was about thirty lines could have made it quite a bit longer/more complicated. ;) The program actually generated Ruby code that was used by another Ruby program to perform the tedious task of writing assembly language for the PIC microcontroller (whew). -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Debian - http://enigmail.mozdev.org iD8DBQFBigJTv24lB609Ih8RAtbdAJsHdHSY7pik1xWT8bYSGkef7sIpqgCfV2JQ QN9AALBzXPT1Puc6DbIx+Sw= =KcEB -----END PGP SIGNATURE-----