aromat 0.1.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69a931058f7a2bfcba4839c6816eedafe8977143
4
- data.tar.gz: 0714cf02e7c3da5db1949bdf5a13e5de1762353a
3
+ metadata.gz: 982f5a3ae19a71b67b88f2e44983efb53e24a464
4
+ data.tar.gz: 4b91df573172ee8f2a4c3d43c9ac677f5fb862e1
5
5
  SHA512:
6
- metadata.gz: 4a1d877ea36647e377a64c28154707b4e71f933a33f9eb28fe045d1f7f85cdbb2f2297cf69b1965e41a177e07bc455e63ecf5b0756e07508deef71debc5a0815
7
- data.tar.gz: 13c3091aacf29e9de3ec1965fa903cb0d50ebe7572ffc7c9404c3342dd7dd43a25c55818b0ed716c56907a42252520cff75f4732613680bcdee17acb65f76955
6
+ metadata.gz: 4b1d806fc9b15f091ca12f9acd8435454241d4fc3be1df71442216651e2241dfda94d5b181540b69bceb828e8138b5f113d1c3a62c57301d7b96383a39e4fcfa
7
+ data.tar.gz: 51bcac4c59eb3b0f0974eb30132590edde0e79f2055d0a7bef59b6e1b0e429df79f1a1c9af0b89da09453c508b106d56564668694249ab5fdb9e46d24d8a0ca9
data/README.md CHANGED
@@ -31,6 +31,24 @@ a.sym_keys
31
31
  # => {:foo=>"bar", :nested=>[{:problems=>"none"}]}
32
32
  ```
33
33
 
34
+ ### Deep-clone
35
+
36
+ A _dclone_ method is monkey-patched into the *Array* and *Hash* classes, and provides a way to recursively *deep-clone* an instance.
37
+
38
+ ```ruby
39
+ a = { foo: 'bar', bar: :kill_me, nested: [{ problems: 'none' }] }
40
+ b = a.dclone
41
+ b[:nested] << :foo
42
+ b[:nested][:problems] = 'no way'
43
+ b[:test] = :bork
44
+ b[:foo] = nil
45
+ b.delete :bar
46
+ a
47
+ # => {:foo=>nil, :nested=>[{:problems=>"no way"}, :foo], :test => :bork}
48
+ b
49
+ # => {:foo=>"bar", :nested=>[{:problems=>"none"}]}
50
+ ```
51
+
34
52
  ## License
35
53
 
36
54
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ # Aromat
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # Aromat Module
5
+ module Aromat
6
+
7
+ # Dclone Module
8
+ module Dclone
9
+
10
+ # Base Clone
11
+ # Clone the object if possible
12
+ def self.base_clone e
13
+ e.is_a?(Symbol) ? e : e.clone
14
+ end
15
+ end
16
+ end
17
+ # Monkey-patch Array Class
18
+ class Array
19
+
20
+ # Deep-Clone
21
+ # Recursively clones every level of the Array
22
+ # @return [Array] A copy of the original array where each element has been clone'd
23
+ def dclone
24
+ collect { |a| a.respond_to?(:dclone) ? a.dclone : Aromat::Dclone.base_clone(a) }
25
+ end
26
+ end
27
+
28
+ # Monkey-patch Hash Class
29
+ class Hash
30
+
31
+ # Deep-Clone
32
+ # Recursively clones every level of the Hash
33
+ # @return [Hash] A copy of the original hash where each element has been clone'd
34
+ def dclone
35
+ Hash[*(inject([]) { |a, e| a + e }.collect { |e| e.respond_to?(:dclone) ? e.dclone : Aromat::Dclone.base_clone(e) })]
36
+ end
37
+ end
@@ -5,5 +5,5 @@
5
5
  module Aromat
6
6
 
7
7
  # Version
8
- VERSION = '0.1.1'
8
+ VERSION = '0.2.1'
9
9
  end
data/lib/aromat.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  # Internal Includes
5
5
  require 'aromat/version'
6
6
  require 'aromat/sym_keys'
7
+ require 'aromat/dclone'
7
8
 
8
9
  # Aromat Module
9
10
  # Root Module for Aromat
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aromat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eresse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - Rakefile
67
67
  - aromat.gemspec
68
68
  - lib/aromat.rb
69
+ - lib/aromat/dclone.rb
69
70
  - lib/aromat/sym_keys.rb
70
71
  - lib/aromat/version.rb
71
72
  homepage: http://redmine.eresse.net/projects/aromat