我正在尝试t
在其他方法中使用变量,传入initialize
. 这是我的学期课程:
class Term
include AASM
attr_accessor :t
def initialize(term)
@t = term
puts self.t
end
aasm do
state :Initialized, :initial => true
state :OrthographyChecked
event :Orthography do
puts "Check Orthography"
# use @t variable here
transitions :from => :Initialized, :to => :UniquenessChecked
end
# .. more events
end
end
term = Term.new("textstring")
我创建了一个新实例,但打印文本的顺序不是我所期望的。我得到:
Check Orthography #from Orthography event
textstring #from initialize method
我不明白为什么最后会触发初始化方法,我@t
也想在aasm do events
. 我怎么能做到这一点,没有@t
得到nil
or t method not found
?