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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7c87ce3266c62021f2ab485feacfcd7f6a612fa
4
- data.tar.gz: d743b0e9354aca2a885d9c3fd4d472df72d66da5
3
+ metadata.gz: df7c69a48af394977dc232bb7ec68d7d0bd38163
4
+ data.tar.gz: 26888c60372728d2a032aeca290b3d3a126b1b5d
5
5
  SHA512:
6
- metadata.gz: 10909f1435a0dcf339c1f47fbd955fe39497834e65a9bd5e31166b9d3ace6505cd4d6291c37c0a471f49f40f3a152b26625891944143a9cbdb77e709d71d8420
7
- data.tar.gz: 299b09b91808ff9219d27f61ebbc3a3a28b14a6b574e4729421cc47e700372481cee73d191662a40ebe5285db0a2ef11f4974665ba27fc0b99190a289a454ef8
6
+ metadata.gz: f9d4dd4c640492cb7a78510c71c18173fb1b5e64230a6a59df6d8d07e5cf60f9b2f4b2689c285001b6a4ae947e0b51230d5ec752bafcdc2872928322bb964d52
7
+ data.tar.gz: 798ca7a624a178726446cf4adc8012fb40d5c9afd01da76e0f97e9e013128bc033163156355444e16e5d0c3420c0e8c70bdc772ea4b8d630bae13e4c45fbe8cc
@@ -0,0 +1,9 @@
1
+ module Rafini
2
+ # In a world where objects are allowed to represent infinities,
3
+ # Rafini dares to introduce empty sets. But WHY!???
4
+ # Ta-ta-TUM...
5
+ module Empty
6
+ ARRAY = [].freeze
7
+ HASH = {}.freeze
8
+ end
9
+ end
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
@@ -1,3 +1,3 @@
1
1
  module Rafini
2
- VERSION = '0.0.0'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/rafini.rb CHANGED
@@ -7,6 +7,7 @@ require 'rafini/integer'
7
7
  require 'rafini/string'
8
8
 
9
9
  require 'rafini/odometers'
10
+ require 'rafini/empty'
10
11
 
11
12
  # Requires:
12
13
  #`ruby`
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.0.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 00:00:00.000000000 Z
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