danielharan-support 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +21 -0
- data/README.rdoc +15 -0
- data/lib/hash_ext.rb +15 -0
- data/support.gemspec +30 -0
- data/test/hash_ext_test.rb +14 -0
- metadata +64 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2008 Daniel Haran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= support
|
2
|
+
|
3
|
+
A place to put these odd bits of ruby core extensions
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
gem install danielharan-support
|
8
|
+
|
9
|
+
It's hosted on github, so you may need to do this first:
|
10
|
+
|
11
|
+
gem sources -a http://gems.github.com
|
12
|
+
|
13
|
+
== License
|
14
|
+
|
15
|
+
Copyright (c) 2008 Daniel Haran - MIT-LICENSE
|
data/lib/hash_ext.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class Hash
|
2
|
+
# Recursively adds hashes
|
3
|
+
# > {:a => 1, :b => 1} + {:a => 1}
|
4
|
+
# => {:a => 2, :b => 1}
|
5
|
+
def +(other)
|
6
|
+
(self.keys + other.keys).uniq.each do |key|
|
7
|
+
if [self[key], other[key]].all?
|
8
|
+
self[key] += other[key]
|
9
|
+
else
|
10
|
+
self[key] ||= other[key] # ignore the nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
data/support.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{support}
|
3
|
+
s.version = "0.1.0"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Daniel Haran"]
|
7
|
+
s.date = %q{2008-12-16}
|
8
|
+
s.description = %q{A collection of ruby core extensions I find useful.}
|
9
|
+
s.email = %q{chebuctonian@gmail.com}
|
10
|
+
s.extra_rdoc_files = ["lib/hash_ext.rb", "README.rdoc"]
|
11
|
+
s.files = ["lib/hash_ext.rb", "Manifest", "MIT-LICENSE", "README.rdoc", "test/hash_ext_test.rb", "support.gemspec"]
|
12
|
+
s.homepage = %q{http://github.com/danielharan/support}
|
13
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Support", "--main", "README.rdoc"]
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.rubyforge_project = %q{support}
|
16
|
+
s.rubygems_version = %q{1.2.0}
|
17
|
+
s.summary = %q{A collection of ruby core extensions I find useful.}
|
18
|
+
s.test_files = ["test/hash_ext_test.rb"]
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 2
|
23
|
+
|
24
|
+
if current_version >= 3 then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require "#{File.dirname(__FILE__)}/../lib/hash_ext"
|
3
|
+
|
4
|
+
class TestReminder < Test::Unit::TestCase
|
5
|
+
def test_simple_addition
|
6
|
+
assert_equal({:a => 2, :b => 1},
|
7
|
+
{:a => 1, :b => 1} + {:a => 1})
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_recursive_addition
|
11
|
+
assert_equal({:a => {:b => 1, :c => 2, :d => 3 }},
|
12
|
+
{:a => {:b => 1, :d => 2}} + {:a => {:c => 2, :d => 1}})
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danielharan-support
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Haran
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-16 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A collection of ruby core extensions I find useful.
|
17
|
+
email: chebuctonian@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/hash_ext.rb
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- lib/hash_ext.rb
|
27
|
+
- Manifest
|
28
|
+
- MIT-LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- test/hash_ext_test.rb
|
31
|
+
- support.gemspec
|
32
|
+
has_rdoc: false
|
33
|
+
homepage: http://github.com/danielharan/support
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --line-numbers
|
37
|
+
- --inline-source
|
38
|
+
- --title
|
39
|
+
- Support
|
40
|
+
- --main
|
41
|
+
- README.rdoc
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "1.2"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project: support
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: A collection of ruby core extensions I find useful.
|
63
|
+
test_files:
|
64
|
+
- test/hash_ext_test.rb
|