safe_clone 0.0.8 → 0.0.9

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: c54291db91a02ba2c6051e1cd100cdfc1ce4a178
4
- data.tar.gz: 8a518a9f94d888be31eb81e00dda2fdfd467ef8a
3
+ metadata.gz: 642d0f06a657cc21e7bdaa95cdaeac8d9007b8eb
4
+ data.tar.gz: a2f40846d9627868b047795003e3cb0959dbe014
5
5
  SHA512:
6
- metadata.gz: b8dce83b680dabab18d8501201528bc07e87676b48abbf935627955fefcbf1b04f32bfadcfa8034211d0c39dfb56b6c77da8923c37691ee4c277cb99062d83a3
7
- data.tar.gz: 0e76392ffc621ad7b5e5890f9bf92ebc5ec14b94fc6a84a1a7cdb54c7ac6c8875d40e3ca0fbf542f798771f05c00a41babc38016ff48cea3490d0280ebab1981
6
+ metadata.gz: 644dca861d95fd253a0648800f54634d4a2371e000515e77184490c63fccb1f4c974863417ff21cf6acb2723d35f7eae63cb98ab06ead5de760f2261405ecbfe
7
+ data.tar.gz: 283e2650a327fe2fbfb217ea6f15cbd1f1d535b7ae95b55398c93f1027a67d1665764998827fb200cbc0d25010878d74f8a593553155939d39e4f08b8cbc35a6
data/README.md CHANGED
@@ -6,9 +6,10 @@ The justification for this uncharacteristic strictness is not at all clear, but
6
6
  it does mean that the clone operation must be applied with great care.
7
7
 
8
8
  Unlike the standard clone method, the safe\_clone method does not throw an
9
- exception when sent to un-clonable value objects like 42 or true. These values
10
- simply return themselves. This is correct because those types of objects do
11
- not _need_ to be cloned. Instead of having a fit, the code just works!
9
+ exception when it sees un-clonable value objects like 42 or true. These values
10
+ simply return themselves. This is deemed correct because those types of objects
11
+ are immutable and do not need to be duped. Instead of raising an exception,
12
+ the code returns the immutable object instead.
12
13
 
13
14
  On a note about performance, this gem does not just rescue the exceptions
14
15
  normally generated by clone, it prevents them from occurring and wasting time
data/lib/safe_clone.rb CHANGED
@@ -2,18 +2,44 @@ require_relative "safe_clone/version"
2
2
 
3
3
  class Object
4
4
  #By default, reference types use the clone method.
5
- def safe_clone; self.clone; end
5
+ def safe_clone
6
+ clone
7
+ end
6
8
  end
7
9
 
8
10
  #For value types, just return self!
9
11
  module SafeClone
10
- def safe_clone; self; end
12
+ def safe_clone
13
+ self
14
+ end
11
15
  end
12
16
 
13
17
  #Update the Ruby value types.
14
- class Numeric; include SafeClone; end
15
- class NilClass; include SafeClone; end
16
- class TrueClass; include SafeClone; end
17
- class FalseClass; include SafeClone; end
18
- class Symbol; include SafeClone; end
19
- class Regexp; include SafeClone; end
18
+ class Numeric
19
+ include SafeClone
20
+ end
21
+
22
+ class NilClass
23
+ include SafeClone
24
+ end
25
+
26
+ class TrueClass
27
+ include SafeClone
28
+ end
29
+
30
+ class FalseClass
31
+ include SafeClone
32
+ end
33
+
34
+ class Symbol
35
+ include SafeClone
36
+ end
37
+
38
+ class Regexp
39
+ include SafeClone
40
+ end
41
+
42
+ class Thread
43
+ include SafeClone
44
+ end
45
+
@@ -1,3 +1,3 @@
1
1
  module SafeClone
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -24,7 +24,7 @@ class SafeCloneTester < Minitest::Test
24
24
  assert_equal((false).safe_clone, false)
25
25
  assert_equal((false).safe_clone.object_id, (false).object_id)
26
26
 
27
- assert_equal((nil).safe_clone, nil)
27
+ assert_nil((nil).safe_clone)
28
28
  assert_equal((nil).safe_clone.object_id, (nil).object_id)
29
29
 
30
30
  rex = /ABC/
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
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-14 00:00:00.000000000 Z
11
+ date: 2018-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -105,10 +105,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.2.3
108
+ rubygems_version: 2.5.2
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A safer version of the clone method.
112
112
  test_files:
113
113
  - test/safe_clone_tests.rb
114
- has_rdoc: