state_machine

https://github.com/pluginaweek/state_machine

Ruby

Adds support for creating state machines for attributes on any Ruby class

StateMachine::StateCollection#matches?

Determines whether the given object is in a specific state.  If the
object's current value doesn't match the state, then this will return
false, otherwise true.  If the given state is unknown, then an IndexError
will be raised.

== Examples

  class Vehicle
    state_machine :initial => :parked do
      other_states :idling
    end
  end
  
  states = Vehicle.state_machine.states
  vehicle = Vehicle.new               # => #<Vehicle:0xb7c464b0 @state="parked">
  
  states.matches?(vehicle, :parked)   # => true
  states.matches?(vehicle, :idling)   # => false
  states.matches?(vehicle, :invalid)  # => IndexError: :invalid is an invalid key for :name index

Source | Google | Stack overflow

Edit

git clone [email protected]:pluginaweek/state_machine.git

cd state_machine

open lib/state_machine/state_collection.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-StateMachine--StateCollection-matches--for-pr


# Commit to git

git add lib/state_machine/state_collection.rbgit commit -m "better docs for StateMachine::StateCollection#matches?"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-StateMachine--StateCollection-matches--for-pr

hub pull-request


# Celebrate!