I readed State Machine Ruby README.md at github.
I want to integrate SM with my Rails application.
However I am curious about what that line does:
before_transition :parked => any - :parked, :do => :put_on_seatbelt
Particulary this fragment looks like ‘magic’ to me:
any - :parked,
Soo, you subtract symbol from some kind of object(s) return by any helper.
How it is suppose to work and what exactly it does this entire line(before_transition ...)?
anyis a singleton instance of theAllMathcher, which represents any state of your model. The minus (“-“) operator is actually an instance method ofAllMatcher(reference here), which excludes the given state from the states of your model.Therefore, if your model has states of
:running,:stopped, and:parked, thenany - :parkedjust returns states:runningand:stopped(:parkedis excluded).And the meaning of the whole statement
before_transition :parked => any - :parked, :do => :put_on_seatbeltis: before the model transits from:parkedto any state but:parked, do the operation:put_on_seatbelt.