diff --git a/lib/workflow/event.rb b/lib/workflow/event.rb index 341c7e5..c425dd7 100644 --- a/lib/workflow/event.rb +++ b/lib/workflow/event.rb @@ -28,9 +28,13 @@ def condition_applicable?(object, event_arguments) object.send(condition, *event_arguments) end else - # since blocks can ignore extra arguments without raising an error in Ruby, - # no `if` is needed - compare with `arity` switch in above methods handling - condition.call(object, *event_arguments) + # Blocks and non-lambda Procs can ignore extra arguments without raising an error in Ruby, + # but lambdas cannot, so we still have to check arity + if condition.arity == 1 # no additional parameters accepted + condition.call(object) + else + condition.call(object, *event_arguments) + end end else true diff --git a/test/conditionals_test.rb b/test/conditionals_test.rb index f4352bb..6f9fae3 100644 --- a/test/conditionals_test.rb +++ b/test/conditionals_test.rb @@ -92,7 +92,8 @@ def check_low_battery?() # supports no arguments, lets test below, what happens event :turn_on, :transitions_to => :low_battery # otherwise end state :on do - event :check, :transitions_to => :low_battery, :if => proc { |obj| return false } + # Use a lambda proc, which enforces correct arity + event :check, :transitions_to => :low_battery, :if => -> (obj) { return false } event :check, :transitions_to => :on # stay in on state otherwise end state :low_battery