safe_dup 0.0.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/lib/safe_dup.rb +10 -5
- data/lib/safe_dup/version.rb +1 -1
- data/rakefile.rb +5 -0
- data/reek.txt +1 -0
- data/safe_dup.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6543761fe95e533d5fad84baf23bfe063d1b6c2c
|
4
|
+
data.tar.gz: 4594e1016d11089e90aeb6ea7749fa19a149e1bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ceba90d313e5e620433d5f12ca232712c4c46adb813eebb39a9ab152c1af5c2af2da3b201992c98ba25a838f9732cc189bf7026e80ffd9454bc3c559d9e7d5d
|
7
|
+
data.tar.gz: 299e3a57d4f6cc37f3cb0b0b2c435c3e28618972b354c3ab855203b37c9fd906b9c3104149b3f92a09aecf432c5881f5fb9ab238f604d4ac671dfe26ca9275a3
|
data/README.md
CHANGED
@@ -7,8 +7,9 @@ it does mean that the dup operation must be applied with great care.
|
|
7
7
|
|
8
8
|
Unlike the standard dup method, the safe\_dup method does not throw an
|
9
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
|
11
|
-
not
|
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 dup, it prevents them from occurring and wasting time
|
@@ -171,6 +172,21 @@ end
|
|
171
172
|
Dup with the safe dup method: 450557.6 i/s
|
172
173
|
Dup with standard dup method: 39436.6 i/s - 11.42x slower
|
173
174
|
|
175
|
+
#### Results: ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
|
176
|
+
Warming up --------------------------------------
|
177
|
+
Dup with standard clone method
|
178
|
+
5.866k i/100ms
|
179
|
+
Dup with the safe clone method
|
180
|
+
23.721k i/100ms
|
181
|
+
Calculating -------------------------------------
|
182
|
+
Dup with standard clone method
|
183
|
+
70.492k (± 0.4%) i/s - 357.826k in 5.076221s
|
184
|
+
Dup with the safe clone method
|
185
|
+
523.478k (± 1.1%) i/s - 2.633M in 5.030544s
|
186
|
+
|
187
|
+
Comparison:
|
188
|
+
Dup with the safe clone method: 523477.8 i/s
|
189
|
+
Dup with standard clone method: 70491.9 i/s - 7.43x slower
|
174
190
|
|
175
191
|
|
176
192
|
Overall: Shorter code _and_ faster. Winner, winner, chicken dinner!
|
data/lib/safe_dup.rb
CHANGED
@@ -2,47 +2,52 @@
|
|
2
2
|
|
3
3
|
require_relative "safe_dup/version"
|
4
4
|
|
5
|
-
# Now you too can dup without fear of annoying exceptions!
|
6
|
-
|
5
|
+
# Now you too can dup objects without fear of annoying exceptions!
|
7
6
|
class Object
|
8
|
-
#By default, reference types use the
|
7
|
+
#By default, reference types use the dup method.
|
9
8
|
def safe_dup
|
10
9
|
dup
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
|
-
#For value types, just return self!
|
13
|
+
# For value types, just return self!
|
15
14
|
module SafeDup
|
16
15
|
def safe_dup
|
17
16
|
self
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
#
|
20
|
+
# Numeric can now safe dup.
|
22
21
|
class Numeric
|
23
22
|
include SafeDup
|
24
23
|
end
|
25
24
|
|
25
|
+
# NilClass can now safe dup.
|
26
26
|
class NilClass
|
27
27
|
include SafeDup
|
28
28
|
end
|
29
29
|
|
30
|
+
# TrueClass can now safe dup.
|
30
31
|
class TrueClass
|
31
32
|
include SafeDup
|
32
33
|
end
|
33
34
|
|
35
|
+
# FalseClass can now safe dup.
|
34
36
|
class FalseClass
|
35
37
|
include SafeDup
|
36
38
|
end
|
37
39
|
|
40
|
+
# Symbols can now safe dup.
|
38
41
|
class Symbol
|
39
42
|
include SafeDup
|
40
43
|
end
|
41
44
|
|
45
|
+
# Regular expressions can now safe dup.
|
42
46
|
class Regexp
|
43
47
|
include SafeDup
|
44
48
|
end
|
45
49
|
|
50
|
+
# Threads can now safe dup.
|
46
51
|
class Thread
|
47
52
|
include SafeDup
|
48
53
|
end
|
data/lib/safe_dup/version.rb
CHANGED
data/rakefile.rb
CHANGED
@@ -8,6 +8,11 @@ Rake::TestTask.new do |t|
|
|
8
8
|
t.verbose = false
|
9
9
|
end
|
10
10
|
|
11
|
+
desc "Run a scan for smelly code!"
|
12
|
+
task :reek do |t|
|
13
|
+
`reek --no-color lib > reek.txt`
|
14
|
+
end
|
15
|
+
|
11
16
|
desc "Fire up an IRB session with safe_dup preloaded."
|
12
17
|
task :console do
|
13
18
|
system "ruby irbt.rb local"
|
data/reek.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0 total warnings
|
data/safe_dup.gemspec
CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency 'minitest', "~> 5.7"
|
24
24
|
spec.add_development_dependency 'minitest_visible', "~> 0.1"
|
25
|
+
spec.add_development_dependency 'reek', "~> 5.0.2"
|
25
26
|
end
|
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: reek
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.0.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.0.2
|
69
83
|
description: A safer version of the dup method that avoids unnecessary exceptions.
|
70
84
|
email:
|
71
85
|
- peter.c.camilleri@gmail.com
|
@@ -83,6 +97,7 @@ files:
|
|
83
97
|
- lib/safe_dup.rb
|
84
98
|
- lib/safe_dup/version.rb
|
85
99
|
- rakefile.rb
|
100
|
+
- reek.txt
|
86
101
|
- safe_dup.gemspec
|
87
102
|
- test/safe_dup_tests.rb
|
88
103
|
homepage: https://github.com/PeterCamilleri/safe_dup
|