Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [ANN] Finite State Ma-thing 0.6

Thread Tools

[ANN] Finite State Ma-thing 0.6

Gavin Kistner
Posts: n/a
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;

Announcing the "Finite State Ma-thing", a base class to make it easy
to implement a state-machine-like jobber.

'Tis a simple class at the core, but a powerful abstraction. (Ruby is
so good at that.)

See the documentation (with pretty picture!) at
RubyLibs/FiniteStateMathing/, which also has a link to the full
source code, and includes an example.

I used this as a proof-of-concept for a half-assed XML parser (behold
the horror! at, that sort of acts
like a SAX parser. I don't know much about Finite State Machines or
their theory, but the beauty of the solutions that FiniteStateMathing
allows is that you _mostly_ use state to figure out what to do, but
also have all the power of instance variables and methods at your
disposal to help you along.

Because I wanted to allow _any_ object as a state, and because I
could not find a way to invoke a class-scoped block to be executed
(with parameter) in the scope of the instance, I'm using the
#define_method hack suggested by Pit Captain, made uglier by me
because (for uniqueness) all the method names are based off of the
#object_id of the state.

This class was mostly an educational exercise for me. Please help
further my education: gimme a holla if you see inefficiencies, have
suggestions for cleaner ways to implement existing code, or envision
cool features or cleaner interfaces.


"When I am working on a problem I never think about beauty. I only
think about how to solve the problem. But when I have finished, if
the solution is not beautiful, I know it is wrong."
- R. Buckminster Fuller


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Safe finite state machine design SomeDude VHDL 3 08-14-2006 12:47 PM
Gate Level model of a Finite state machine Inderkal VHDL 8 12-09-2004 11:17 PM
How to sequencialize two finite state machines ? Martin Maurer VHDL 3 06-14-2004 07:40 AM
How to implement linked Finite State Machines Sidney Cadot VHDL 0 04-18-2004 10:45 AM
HELP PLEASE!! - Finite State Machine - Automaton - Microprogrammed System deejayfred VHDL 0 10-02-2003 01:23 AM