full_clone 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5671e38cbd5b3f7214be72da4d3e5d183a41d7d
4
- data.tar.gz: 174f1e3f0e7279565e2843a88e59665df9c184b2
3
+ metadata.gz: 97944e660887dfe2a84d165cb26d2dc6e97b8b40
4
+ data.tar.gz: 9e03f91b6587a868fec985a1955c8d3697af0015
5
5
  SHA512:
6
- metadata.gz: 6871aaf141f6c9c4c44cc9b3ab6fca0d56b39544a7fe7b0b87f96ea554d5ee8cd01636bf0dcd2d0c9bf2e67f5875ff4104d0f72887287ba73270d3d90fec8da0
7
- data.tar.gz: ee7830f9882649c34c2d063638fe08b0391855d11c732ca81010158d915841191ddbc08d9a4afe22e398af5909d6404c9a7b4dd765325247a582be7bee3cabe2
6
+ metadata.gz: 8bbbad200de9137bdb3ab810fdddbba2dd7b0e0eb993d7aaef6409ab1817e8f6efcab2b8eeb17d2e102a9cabab0da1b175209452a469fd2cf54da103ff081691
7
+ data.tar.gz: 9bada8380789f7227a6a809a1bf9393fb8ba1e035e9446adb1c6df7b90eaf3ef9474dfaeac3ec267035f965f7e95d52862c1028d25abc34879b7971bfa3cf9e3
data/README.md CHANGED
@@ -6,6 +6,8 @@ cloned copy. The full_clone method digs deep and makes copies of these internal
6
6
  variables, not just arrays and hashes. It also allows classes to specify an
7
7
  exclusion list of variables that are not to be processed.
8
8
 
9
+ New for version 0.0.10, now 84% faster (at least full_dup was in my tests).
10
+
9
11
  This comprehensive approach creates another issue to be resolved. In Ruby, if an
10
12
  attempt is made to clone an immutable data item like a number, an error occurs.
11
13
  The justification for this uncharacteristic strictness is not at all clear, but
data/lib/full_clone.rb CHANGED
@@ -1,37 +1,11 @@
1
1
  # coding: utf-8
2
2
 
3
+ # A deep, safe, recursive variant of the clone method. The full_clone method.
4
+
5
+ require_relative 'full_clone/use_self'
6
+ require_relative 'full_clone/use_clone'
3
7
  require_relative 'full_clone/version'
4
8
  require_relative 'full_clone/object'
5
9
  require_relative 'full_clone/array'
6
10
  require_relative 'full_clone/hash'
7
11
  require_relative 'full_clone/struct'
8
-
9
- module FullClone
10
- def full_clone(_progress={})
11
- self
12
- end
13
- end
14
-
15
- class Numeric
16
- include FullClone
17
- end
18
-
19
- class NilClass
20
- include FullClone
21
- end
22
-
23
- class TrueClass
24
- include FullClone
25
- end
26
-
27
- class FalseClass
28
- include FullClone
29
- end
30
-
31
- class Symbol
32
- include FullClone
33
- end
34
-
35
- class Regexp
36
- include FullClone
37
- end
@@ -5,14 +5,20 @@ class Array
5
5
  progress[object_id] = result = clone
6
6
  exclude = full_clone_exclude
7
7
 
8
- each_index do |name|
9
-
10
- unless exclude.include?(name)
8
+ if exclude.empty?
9
+ each_index do |name|
11
10
  value = result[name]
12
11
  value = progress[value.object_id] || value.full_clone(progress)
13
12
  result[name] = value
14
13
  end
15
-
14
+ else
15
+ each_index do |name|
16
+ unless exclude.include?(name)
17
+ value = result[name]
18
+ value = progress[value.object_id] || value.full_clone(progress)
19
+ result[name] = value
20
+ end
21
+ end
16
22
  end
17
23
 
18
24
  result
@@ -5,14 +5,20 @@ class Hash
5
5
  progress[object_id] = result = clone
6
6
  exclude = full_clone_exclude
7
7
 
8
- each_key do |name|
9
-
10
- unless exclude.include?(name)
8
+ if exclude.empty?
9
+ each_key do |name|
11
10
  value = result[name]
12
11
  value = progress[value.object_id] || value.full_clone(progress)
13
12
  result[name] = value
14
13
  end
15
-
14
+ else
15
+ each_key do |name|
16
+ unless exclude.include?(name)
17
+ value = result[name]
18
+ value = progress[value.object_id] || value.full_clone(progress)
19
+ result[name] = value
20
+ end
21
+ end
16
22
  end
17
23
 
18
24
  result
@@ -10,14 +10,20 @@ class Object
10
10
  progress[object_id] = result = clone
11
11
  exclude = full_clone_exclude
12
12
 
13
- instance_variables.each do |name|
14
-
15
- unless exclude.include?(name)
13
+ if exclude.empty?
14
+ instance_variables.each do |name|
16
15
  value = result.instance_variable_get(name)
17
16
  value = progress[value.object_id] || value.full_clone(progress)
18
17
  result.instance_variable_set(name, value)
19
18
  end
20
-
19
+ else
20
+ instance_variables.each do |name|
21
+ unless exclude.include?(name)
22
+ value = result.instance_variable_get(name)
23
+ value = progress[value.object_id] || value.full_clone(progress)
24
+ result.instance_variable_set(name, value)
25
+ end
26
+ end
21
27
  end
22
28
 
23
29
  result
@@ -5,14 +5,20 @@ class Struct
5
5
  progress[object_id] = result = clone
6
6
  exclude = full_clone_exclude
7
7
 
8
- members.each do |name|
9
-
10
- unless exclude.include?(name)
8
+ if exclude.empty?
9
+ members.each do |name|
11
10
  value = result[name]
12
11
  value = progress[value.object_id] || value.full_clone(progress)
13
12
  result[name] = value
14
13
  end
15
-
14
+ else
15
+ members.each do |name|
16
+ unless exclude.include?(name)
17
+ value = result[name]
18
+ value = progress[value.object_id] || value.full_clone(progress)
19
+ result[name] = value
20
+ end
21
+ end
16
22
  end
17
23
 
18
24
  result
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ module FullCloneClone
4
+ def full_clone(_progress=nil)
5
+ clone
6
+ end
7
+ end
8
+
9
+ class String
10
+ include FullCloneClone
11
+ end
12
+
13
+ class Enumerator
14
+ include FullCloneClone
15
+ end
16
+
17
+ class MatchData
18
+ include FullCloneClone
19
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ module FullCloneSelf
4
+ def full_clone(_progress=nil)
5
+ self
6
+ end
7
+ end
8
+
9
+ class Numeric
10
+ include FullCloneSelf
11
+ end
12
+
13
+ class NilClass
14
+ include FullCloneSelf
15
+ end
16
+
17
+ class TrueClass
18
+ include FullCloneSelf
19
+ end
20
+
21
+ class FalseClass
22
+ include FullCloneSelf
23
+ end
24
+
25
+ class Symbol
26
+ include FullCloneSelf
27
+ end
28
+
29
+ class Regexp
30
+ include FullCloneSelf
31
+ end
32
+
33
+ class Thread
34
+ include FullCloneSelf
35
+ end
36
+
@@ -1,3 +1,3 @@
1
1
  module FullClone
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/test/array_tests.rb CHANGED
@@ -18,7 +18,7 @@ class ArrayFullCloneTester < Minitest::Test
18
18
 
19
19
  assert_equal(simple1[0], simple2[0])
20
20
  assert_equal(simple1[1], 5)
21
- assert_equal(simple1[2], nil)
21
+ assert_nil(simple1[2])
22
22
  refute_equal(simple1[0].object_id, simple2[0].object_id)
23
23
 
24
24
  sa << "West"
@@ -38,7 +38,7 @@ class ArrayFullCloneTester < Minitest::Test
38
38
 
39
39
  assert_equal(simple1[0], simple2[0])
40
40
  assert_equal(simple1[1], 5)
41
- assert_equal(simple1[2], nil)
41
+ assert_nil(simple1[2])
42
42
  assert_equal(simple1[0].object_id, simple2[0].object_id)
43
43
  end
44
44
 
@@ -24,7 +24,7 @@ class FullCloneTester < Minitest::Test
24
24
  assert_equal((false).full_clone, false)
25
25
  assert_equal((false).full_clone.object_id, (false).object_id)
26
26
 
27
- assert_equal((nil).full_clone, nil)
27
+ assert_nil((nil).full_clone)
28
28
  assert_equal((nil).full_clone.object_id, (nil).object_id)
29
29
 
30
30
  rex = /ABC/
data/test/hash_tests.rb CHANGED
@@ -18,7 +18,7 @@ class HashFullCloneTester < Minitest::Test
18
18
 
19
19
  assert_equal(simple1[:iva], simple2[:iva])
20
20
  assert_equal(simple1[:ivb], 5)
21
- assert_equal(simple1[:ivc], nil)
21
+ assert_nil(simple1[:ivc])
22
22
  refute_equal(simple1[:iva].object_id, simple2[:iva].object_id)
23
23
 
24
24
  sa << "West"
@@ -38,7 +38,7 @@ class HashFullCloneTester < Minitest::Test
38
38
 
39
39
  assert_equal(simple1[:iva], simple2[:iva])
40
40
  assert_equal(simple1[:ivb], 5)
41
- assert_equal(simple1[:ivc], nil)
41
+ assert_nil(simple1[:ivc])
42
42
  assert_equal(simple1[:iva].object_id, simple2[:iva].object_id)
43
43
  end
44
44
 
data/test/object_tests.rb CHANGED
@@ -28,7 +28,7 @@ class ObjectFullCloneTester < Minitest::Test
28
28
 
29
29
  assert_equal(simple1.iva, simple2.iva)
30
30
  assert_equal(simple1.ivb, 5)
31
- assert_equal(simple1.ivc, nil)
31
+ assert_nil(simple1.ivc)
32
32
  refute_equal(simple1.iva.object_id, simple2.iva.object_id)
33
33
 
34
34
  sa << "West"
@@ -48,7 +48,7 @@ class ObjectFullCloneTester < Minitest::Test
48
48
 
49
49
  assert_equal(simple1.iva, simple2.iva)
50
50
  assert_equal(simple1.ivb, 5)
51
- assert_equal(simple1.ivc, nil)
51
+ assert_nil(simple1.ivc)
52
52
  assert_equal(simple1.iva.object_id, simple2.iva.object_id)
53
53
  end
54
54
 
data/test/struct_tests.rb CHANGED
@@ -20,7 +20,7 @@ class StructFullCloneTester < Minitest::Test
20
20
 
21
21
  assert_equal(simple1.iva, simple2.iva)
22
22
  assert_equal(simple1.ivb, 5)
23
- assert_equal(simple1.ivc, nil)
23
+ assert_nil(simple1.ivc)
24
24
  refute_equal(simple1.iva.object_id, simple2.iva.object_id)
25
25
 
26
26
  sa << "West"
@@ -40,7 +40,7 @@ class StructFullCloneTester < Minitest::Test
40
40
 
41
41
  assert_equal(simple1.iva, simple2.iva)
42
42
  assert_equal(simple1.ivb, 5)
43
- assert_equal(simple1.ivc, nil)
43
+ assert_nil(simple1.ivc)
44
44
  assert_equal(simple1.iva.object_id, simple2.iva.object_id)
45
45
  end
46
46
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: full_clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2018-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -86,6 +86,8 @@ files:
86
86
  - lib/full_clone/hash.rb
87
87
  - lib/full_clone/object.rb
88
88
  - lib/full_clone/struct.rb
89
+ - lib/full_clone/use_clone.rb
90
+ - lib/full_clone/use_self.rb
89
91
  - lib/full_clone/version.rb
90
92
  - rakefile.rb
91
93
  - test/array_tests.rb
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  version: '0'
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 2.2.3
118
+ rubygems_version: 2.5.2
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: A clone variant that performs a deep copy.
@@ -123,4 +125,3 @@ test_files:
123
125
  - test/hash_tests.rb
124
126
  - test/object_tests.rb
125
127
  - test/struct_tests.rb
126
- has_rdoc: