rafini 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rafini/empty.rb +9 -0
- data/lib/rafini/hash.rb +46 -0
- data/lib/rafini/version.rb +1 -1
- data/lib/rafini.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df7c69a48af394977dc232bb7ec68d7d0bd38163
|
4
|
+
data.tar.gz: 26888c60372728d2a032aeca290b3d3a126b1b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d4dd4c640492cb7a78510c71c18173fb1b5e64230a6a59df6d8d07e5cf60f9b2f4b2689c285001b6a4ae947e0b51230d5ec752bafcdc2872928322bb964d52
|
7
|
+
data.tar.gz: 798ca7a624a178726446cf4adc8012fb40d5c9afd01da76e0f97e9e013128bc033163156355444e16e5d0c3420c0e8c70bdc772ea4b8d630bae13e4c45fbe8cc
|
data/lib/rafini/empty.rb
ADDED
data/lib/rafini/hash.rb
CHANGED
@@ -7,6 +7,52 @@ module Rafini
|
|
7
7
|
def to_struct
|
8
8
|
Struct.new(*self.keys).new(*self.values)
|
9
9
|
end
|
10
|
+
|
11
|
+
# hash0.modify(hash1,...) #=> hash
|
12
|
+
#
|
13
|
+
# Updates hash with hashes.
|
14
|
+
# Overwrites existing elements and adds elements.
|
15
|
+
# {a:'A',b:'B'}.modify({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X',c:'Y',d:'D'}
|
16
|
+
def modify(*hashes)
|
17
|
+
hashes.each do |hash|
|
18
|
+
hash.each do |key, value|
|
19
|
+
self[key] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
# hash0.supplement(hash1,...) #=> hash
|
26
|
+
#
|
27
|
+
# Supplements hash with hashes.
|
28
|
+
# Adds missing elements only.
|
29
|
+
# {a:'A',b:'B'}.supplement({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'B',c:'C',d:'D'}
|
30
|
+
def supplement(*hashes)
|
31
|
+
hashes.each do |hash|
|
32
|
+
hash.each do |key, value|
|
33
|
+
self[key] = value unless self.has_key?(key)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
# hash0.ammend(hash1,...)
|
40
|
+
#
|
41
|
+
# Ammends hash with hashes.
|
42
|
+
# Overwrites existing elements only.
|
43
|
+
# {a:'A',b:'B'}.supplement({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X'}
|
44
|
+
def ammend(*hashes)
|
45
|
+
self.keys.each do |key|
|
46
|
+
hashes.each do |hash|
|
47
|
+
if hash.has_key?(key)
|
48
|
+
self[key] = hash[key]
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
10
56
|
end
|
11
57
|
end
|
12
58
|
end
|
data/lib/rafini/version.rb
CHANGED
data/lib/rafini.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rafini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Just a collection of useful refinements.
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- README.rdoc
|
22
22
|
- lib/rafini.rb
|
23
23
|
- lib/rafini/array.rb
|
24
|
+
- lib/rafini/empty.rb
|
24
25
|
- lib/rafini/exception.rb
|
25
26
|
- lib/rafini/hash.rb
|
26
27
|
- lib/rafini/integer.rb
|