state is a library for implementing first-class states on arbitrary owner objects.
There’s an incredible amount of funtionality described in the very extensive documentation.
state() method on the affected object.
As much as possible, State should aim to look and feel like a feature of the language. The interpreted shorthand syntax, simple keyword attributes, and limited interface should allow for production code that is terse, declarative, and easy to write and understand.
Apart from the addition of the
object.state() method, a call to
state() must make no other modifications to a State–affected object’s interface. Methods are replaced with delegators, which forward method calls to the current state. This is to be implemented opaquely and non-destructively: consumers of the object need not be aware of which states are active in the object, or even that a concept of state exists at all, and a call to
object.state('').destroy() must restore the object to its original form.
There are plenty of examples and information on the documentation site. Check it out!