Use Ruby's initialize_copy for clone/dup

Ruby provides a method for implementing deep-copy on
objects called initialize_copy. This gets called after
a clone or dup, and is the more idiomatic way to handle
the sort of thing being done in the previously-defined
clone method.
This commit is contained in:
Ernie Miller 2012-06-27 08:44:48 -04:00
parent 949bb42a4d
commit 129f2da60a
1 changed files with 6 additions and 7 deletions

View File

@ -19,11 +19,10 @@ module AASM
@config = OpenStruct.new
end
def clone
klone = super
klone.states = states.clone
klone.events = events.clone
klone
def initialize_copy(orig)
super
@states = @states.dup
@events = @events.dup
end
def create_state(name, options)