state_machine
https://github.com/pluginaweek/state_machine
Ruby
Adds support for creating state machines for attributes on any Ruby class
StateMachine::State#matches?
Determines whether this state matches the given value. If no matcher is
configured, then this will check whether the values are equivalent.
Otherwise, the matcher will determine the result.
For example,
# Without a matcher
state = State.new(machine, :parked, :value => 1)
state.matches?(1) # => true
state.matches?(2) # => false
# With a matcher
state = State.new(machine, :parked, :value => lambda {Time.now}, :if => lambda {|value| !value.nil?})
state.matches?(nil) # => false
state.matches?(Time.now) # => trueEdit
git clone [email protected]:pluginaweek/state_machine.git
cd state_machine
open lib/state_machine/state.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-StateMachine--State-matches--for-pr
# Commit to gitgit add lib/state_machine/state.rbgit commit -m "better docs for StateMachine::State#matches?"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-StateMachine--State-matches--for-pr
hub pull-request
# Celebrate!