homeschool 0.0.1.21 → 0.0.1.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/homeschool.rb +8 -1
  2. data/test/the_test.rb +10 -0
  3. metadata +3 -2
data/lib/homeschool.rb CHANGED
@@ -131,9 +131,16 @@ class Hash
131
131
 
132
132
  def filter(*keys)
133
133
  keys.inject({}) do |h, key|
134
- h[key] = self[key]; h
134
+ h[key] = self[key] if has_key?(key); h
135
135
  end
136
136
  end
137
+
138
+ def match(regexp)
139
+ inject({}) do |h, (key, value)|
140
+ h[key] = value if key.to_s =~ regexp; h
141
+ end
142
+ end
143
+
137
144
  def list(*keys)
138
145
  keys.collect &method(:[])
139
146
  end
data/test/the_test.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + "/../lib/homeschool"
3
+
4
+ class TheTest < Test::Unit::TestCase
5
+ def test_hash_filter
6
+ hash = {:one => 1, :two => 2, :three => 3}
7
+ assert_equal({:one => 1, :three => 3}, hash.filter(:one, :three, :four))
8
+ assert_equal({:two => 2, :three => 3}, hash.match(/t/))
9
+ end
10
+ end
metadata CHANGED
@@ -1,9 +1,9 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: homeschool
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1.21
6
+ version: 0.0.1.22
7
7
  date: 2007-09-11 00:00:00 -04:00
8
8
  summary: The homeschool gem
9
9
  require_paths:
@@ -36,6 +36,7 @@ files:
36
36
  - bin/gfight
37
37
  - bin/homeschool
38
38
  - bin/svm
39
+ - test/the_test.rb
39
40
  - lib/fight.rb
40
41
  - lib/form_buildr.rb
41
42
  - lib/homeschool.rb