[ANN] Finite State Ma-thing 0.6

Discussion in 'Ruby' started by Gavin Kistner, May 27, 2005.

  1. --Apple-Mail-1--730316079
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain;
    charset=US-ASCII;
    delsp=yes;
    format=flowed

    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 http://phrogz.net/
    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 http://phrogz.net/tmp/XML_FSM.png), 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.

    Enjoy!

    --
    "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


    --Apple-Mail-1--730316079--
     
    Gavin Kistner, May 27, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. deejayfred
    Replies:
    0
    Views:
    581
    deejayfred
    Oct 2, 2003
  2. Sidney Cadot
    Replies:
    0
    Views:
    2,417
    Sidney Cadot
    Apr 18, 2004
  3. SomeDude
    Replies:
    3
    Views:
    3,217
    arant
    Aug 14, 2006
  4. Martin Maurer
    Replies:
    3
    Views:
    688
    Andrew Hall
    Jun 14, 2004
  5. Henrik Vallgren
    Replies:
    0
    Views:
    803
    Henrik Vallgren
    Jun 15, 2004
Loading...

Share This Page