Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors
Jun 27, 2012
Ernie Miller 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.
129f2da
Jun 28, 2012
Thorsten Böttger Merge pull request #51 from ernie/intialize-copy
Use Ruby's initialize_copy for clone/dup
2139407

Showing 1 changed file with 6 additions and 7 deletions. Show diff stats Hide diff stats

  1. 13  lib/aasm/state_machine.rb
13  lib/aasm/state_machine.rb
@@ -3,11 +3,11 @@ class StateMachine
3 3
     def self.[](clazz)
4 4
       (@machines ||= {})[clazz.to_s]
5 5
     end
6  
-  
  6
+
7 7
     def self.[]=(clazz, machine)
8 8
       (@machines ||= {})[clazz.to_s] = machine
9 9
     end
10  
-  
  10
+
11 11
     attr_accessor :states, :events, :initial_state, :config
12 12
     attr_reader :name
13 13
 
@@ -19,11 +19,10 @@ def initialize(name)
19 19
       @config = OpenStruct.new
20 20
     end
21 21
 
22  
-    def clone
23  
-      klone = super
24  
-      klone.states = states.clone
25  
-      klone.events = events.clone
26  
-      klone
  22
+    def initialize_copy(orig)
  23
+      super
  24
+      @states = @states.dup
  25
+      @events = @events.dup
27 26
     end
28 27
 
29 28
     def create_state(name, options)

No commit comments for this range

Something went wrong with that request. Please try again.