state_machines
state_machines copied to clipboard
Passing event kwargs to guards option
Add passing kwargs from event to guard
class Vehicle
state_machine :state, initial: :parked do
...
event :crash do
transition all - [:parked, :stalled] => :stalled, if: ->(vehicle, kwargs) {kwargs[:arg] == true} # kwargs from event fire
end
end
end
vehicle = Vehicle.new
vehicle.crash(arg: false) # false