mug 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mug/hashop.rb +15 -0
  3. data/test/test-hashop.rb +12 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c132b6a79488019536300de12dc918fe41191b9
4
- data.tar.gz: 94c1e037fe68407949e3c3bcd0d4274c5cf8eb5d
3
+ metadata.gz: 096507698665e2384dc75549dc0c691729153514
4
+ data.tar.gz: cd4bb09ea9fadf13be4494abdb18b648854eac44
5
5
  SHA512:
6
- metadata.gz: dfc72b0fa90e4b518499912838f5619ae95380a8a7b18194e00a44bf788b0f24ed3cc08ce3ae218b3943a18616a5e2d9f82db15247cfab7abd44ccc12da13111
7
- data.tar.gz: 1b0c0f63d50b07197f1db75ee2f849f08c1264bc7add2a02056b4ecd1bae619f95680051b254093ae45fb2de3f1a475e1ed204490ad581edf5c1a674a3bb260b
6
+ metadata.gz: 099c99f1bbe1bf272c7d44cf7b32777183f93670c2d5e01854824ce54ab1c7f91e12a327dd217fe93f351214d719dd2439a3d74026f3a96d6d5aea40b5dcd94a
7
+ data.tar.gz: a5d64be2b7b44cba756eed062d11413a265c99d21b8ae4d15dcb3e46b057b1a111fa0b7809afd70c58503ff53430429e7f57a7ddda7af289febaaa3124f78af8
@@ -16,6 +16,15 @@ class Hash
16
16
  o.merge self
17
17
  end
18
18
 
19
+ #
20
+ # Adds the contents of +other_hash+ to +hsh+.
21
+ # Entries with duplicate keys are overwritten with the
22
+ # values from +other_hash+
23
+ #
24
+ def + other_hash
25
+ merge other_hash
26
+ end
27
+
19
28
  #
20
29
  # Appends stuff to the hash.
21
30
  #
@@ -24,6 +33,12 @@ class Hash
24
33
  # If +o+ can be converted to a hash with #to_h, this is identical to calling #merge!
25
34
  # Otherwise an ArgumentError is raised.
26
35
  #
36
+ # Example:
37
+ # h = {}
38
+ # h << {:a=>0} # h = {:a=>0}
39
+ # h << {:b=>2,:c=>3} # h = {:a=>0,:b=>2,:c=>3}
40
+ # h << [:a,1] # h = {:a=>1,:b=>2,:c=>3}
41
+ #
27
42
  def << o
28
43
  if o.respond_to? :to_hash
29
44
  merge! o.to_hash
@@ -20,6 +20,18 @@ class Test_hashop < Test::Unit::TestCase
20
20
  assert_equal( a|b, x )
21
21
  end
22
22
  end
23
+ def test_hash_plus
24
+ h = { :a => 1, :b => 2 }
25
+ [
26
+ [{}, h, h],
27
+ [{:c=>3}, h, {:a=>1, :b=>2, :c=>3}],
28
+ [{:a=>0, :b=>0}, h, h],
29
+ [{:a=>0, :c=>3}, h, {:a=>1, :b=>2, :c=>3}],
30
+ [h, {}, h],
31
+ ].each do |a, b, x|
32
+ assert_equal( a+b, x )
33
+ end
34
+ end
23
35
  def test_hash_poke
24
36
  h = {}
25
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  == MUG: Matty's Ultimate Gem