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 +4 -4
- data/README.md +4 -3
- data/lib/safe_clone.rb +34 -8
- data/lib/safe_clone/version.rb +1 -1
- data/test/safe_clone_tests.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642d0f06a657cc21e7bdaa95cdaeac8d9007b8eb
|
4
|
+
data.tar.gz: a2f40846d9627868b047795003e3cb0959dbe014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
10
|
-
simply return themselves. This is correct because those types of objects
|
11
|
-
not
|
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
|
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
|
12
|
+
def safe_clone
|
13
|
+
self
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
#Update the Ruby value types.
|
14
|
-
class Numeric
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
class
|
19
|
-
|
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
|
+
|
data/lib/safe_clone/version.rb
CHANGED
data/test/safe_clone_tests.rb
CHANGED
@@ -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
|
-
|
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.
|
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:
|
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
|
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:
|