hash_ext 0.2.0 → 0.2.1

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: 8f9ae9f704e9ea7ee1f52968bbbc23bc94e0d1e9
4
- data.tar.gz: facfc3a675152c71e3edd6d32402b7694886678e
3
+ metadata.gz: 65fdcdef6f30c72fd67f580a85b229dc482436db
4
+ data.tar.gz: 134b5b4bb3473bb91a70086944083d59bd863496
5
5
  SHA512:
6
- metadata.gz: 8a31b105fc8bccb7f15314327cc0001b6443987f344177a296380a8ceacd7e2aeb8c35a258cfa1e7ef05c5b70996b1946c3f252fadd583eb750f513da9be17a0
7
- data.tar.gz: 3cf7ad00240b033eb6f559b916e98f41b518fbd958e1245751566e143472e37656ba1c8be31918fafc119672cdebf18dd571e8dcc1d4e7f661645cbfe87c5774
6
+ metadata.gz: 922fc626a447c9d1a10630bec09f1276321e776b400e547ff867d054caf3662cb4799995fc6746a88047f3ed06570f72dbe00d846385741bbbe1b45923d09e4d
7
+ data.tar.gz: 15d7e5d4a95549accc7328a6a091b1411431e26b5a401aa7b086d6310bf41aefafb6e2992449ddb4a28ffc82c5219ebdfe16a542591e6e5e56d0780323d52e85
@@ -1,24 +1,41 @@
1
1
  class Hash
2
2
  class Accessible < Indifferent
3
3
 
4
+ def self.make_accessible(value)
5
+ if value.kind_of? Hash
6
+ self.new value
7
+ elsif value.kind_of? ::Array
8
+ Array.new value
9
+ else
10
+ value
11
+ end
12
+ end
13
+
14
+ class Array < SimpleDelegator
15
+
16
+ def initialize(array)
17
+ super array.map { |v| Accessible.make_accessible v }
18
+ end
19
+
20
+ def push(value)
21
+ super Accessible.make_accessible(value)
22
+ end
23
+ alias_method :<<, :push
24
+
25
+ end
26
+
27
+ def []=(key, value)
28
+ super key, self.class.make_accessible(value)
29
+ end
30
+
4
31
  private
5
32
 
6
33
  def method_missing(method, *args, &block)
7
34
  if method.to_s.end_with? '='
8
35
  key = method[0..-2]
9
- self[key] = make_accessible args[0]
10
- else
11
- make_accessible self[method]
12
- end
13
- end
14
-
15
- def make_accessible(value)
16
- if value.kind_of? Hash
17
- self.class.new value
18
- elsif value.kind_of? Array
19
- value.map { |v| make_accessible v }
36
+ self[key] = args[0]
20
37
  else
21
- value
38
+ self[method]
22
39
  end
23
40
  end
24
41
 
@@ -1,3 +1,3 @@
1
1
  module HashExt
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler