safe_dup 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/safe_dup.rb +35 -8
- data/lib/safe_dup/version.rb +1 -1
- data/test/safe_dup_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: 3a1fa2f5d277d5480f6b45c11dbc355badc3cd56
|
4
|
+
data.tar.gz: ca7ff2caadc69bcb635e31292cd1677b9f354be3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef8ee0f8eb380f082276c531d2a1b37b2e6847f2db6903d2d46811b2bb66fe31d0c0c0d605561bcfa8fc432d49d674cb744c9546e489925e395ff6264a73dda
|
7
|
+
data.tar.gz: a2ded1a54ee443f2c3cd21a804fd2bf5a10654128bc1c2b261533197f9405301293ee16b5158259dd23edd9279e9a094c43c5094370d0d9e67f9656d5ce1567b
|
data/lib/safe_dup.rb
CHANGED
@@ -1,21 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
require_relative "safe_dup/version"
|
3
4
|
|
5
|
+
# Now you too can dup without fear of annoying exceptions!
|
6
|
+
|
4
7
|
class Object
|
5
8
|
#By default, reference types use the clone method.
|
6
|
-
def safe_dup
|
9
|
+
def safe_dup
|
10
|
+
dup
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
#For value types, just return self!
|
10
15
|
module SafeDup
|
11
|
-
def safe_dup
|
16
|
+
def safe_dup
|
17
|
+
self
|
18
|
+
end
|
12
19
|
end
|
13
20
|
|
14
21
|
#Update the Ruby value types.
|
15
|
-
class Numeric
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
class
|
20
|
-
|
22
|
+
class Numeric
|
23
|
+
include SafeDup
|
24
|
+
end
|
25
|
+
|
26
|
+
class NilClass
|
27
|
+
include SafeDup
|
28
|
+
end
|
21
29
|
|
30
|
+
class TrueClass
|
31
|
+
include SafeDup
|
32
|
+
end
|
33
|
+
|
34
|
+
class FalseClass
|
35
|
+
include SafeDup
|
36
|
+
end
|
37
|
+
|
38
|
+
class Symbol
|
39
|
+
include SafeDup
|
40
|
+
end
|
41
|
+
|
42
|
+
class Regexp
|
43
|
+
include SafeDup
|
44
|
+
end
|
45
|
+
|
46
|
+
class Thread
|
47
|
+
include SafeDup
|
48
|
+
end
|
data/lib/safe_dup/version.rb
CHANGED
data/test/safe_dup_tests.rb
CHANGED
@@ -24,7 +24,7 @@ class SafeDupTester < Minitest::Test
|
|
24
24
|
assert_equal((false).safe_dup, false)
|
25
25
|
assert_equal((false).safe_dup.object_id, (false).object_id)
|
26
26
|
|
27
|
-
|
27
|
+
assert_nil((nil).safe_dup)
|
28
28
|
assert_equal((nil).safe_dup.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_dup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
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-06 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 dup method.
|
112
112
|
test_files:
|
113
113
|
- test/safe_dup_tests.rb
|
114
|
-
has_rdoc:
|