我有以下状态:A,,,:B。:C
require 'state_machine'
class Example
property :value, String
def test_condition
value == "hmm"
end
state_machine :state, :initial => :A do
event :my_event do
transition [:A, :B] => :C, :if => :test_condition
transition :A => :B, :unless => :test_condition
end
end
def my_event
#Some Logic
end
end
当:test_condition为真时,状态从:Ato:C但当它为假时,两个状态都从:Ato :B,问题是当我的状态被触发时:B,:my_event在这种情况下,状态不会变为:C并停留在:B。我错过了什么吗?
我使用 rubymine 调试了我的代码,发现当状态为 at:B并触发事件时,断点不会在:test_condition方法处停止;它根本不会被调用。
文档一次只讨论iforelse一次,没有提到与if State_1 else State_2.