Circumvent "instance variable not defined" warnings

Fixes #583
This commit is contained in:
Paul Cantrell 2018-03-02 12:10:38 -06:00 committed by Anil Kumar Maurya
parent 26219482f7
commit 97e1fa501d
1 changed files with 2 additions and 1 deletions

View File

@ -5,7 +5,8 @@ module AASM
# may be overwritten by persistence mixins
def aasm_read_state(name=:default)
# all the following lines behave like @current_state ||= aasm(name).enter_initial_state
current = aasm(name).instance_variable_get("@current_state_#{name}")
current = aasm(name).instance_variable_defined?("@current_state_#{name}") &&
aasm(name).instance_variable_get("@current_state_#{name}")
return current if current
aasm(name).instance_variable_set("@current_state_#{name}", aasm(name).enter_initial_state)
end