map 6.4.0 → 6.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/map.rb +24 -3
  2. data/map.gemspec +1 -1
  3. data/test/map_test.rb +10 -0
  4. metadata +2 -2
data/lib/map.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class Map < Hash
3
- Version = '6.4.0' unless defined?(Version)
3
+ Version = '6.4.1' unless defined?(Version)
4
4
  Load = Kernel.method(:load) unless defined?(Load)
5
5
 
6
6
  class << Map
@@ -169,6 +169,21 @@ class Map < Hash
169
169
  def match(haystack, needle)
170
170
  intersection(haystack, needle) == needle
171
171
  end
172
+
173
+ def args_for_arity(args, arity)
174
+ arity = Integer(arity.respond_to?(:arity) ? arity.arity : arity)
175
+ arity < 0 ? args.dup : args.slice(0, arity)
176
+ end
177
+
178
+ def call(object, method, *args, &block)
179
+ args = Map.args_for_arity(args, object.method(method).arity)
180
+ object.send(method, *args, &block)
181
+ end
182
+
183
+ def bcall(*args, &block)
184
+ args = Map.args_for_arity(args, block.arity)
185
+ block.call(*args)
186
+ end
172
187
  end
173
188
 
174
189
  # instance constructor
@@ -414,10 +429,16 @@ class Map < Hash
414
429
  super
415
430
  end
416
431
 
417
- def delete_if
432
+ def delete_if(&block)
418
433
  to_delete = []
419
- keys.each{|key| to_delete.push(key) if yield(key)}
434
+
435
+ each do |key, val|
436
+ args = [key, val]
437
+ to_delete.push(key) if !!Map.bcall(*args, &block)
438
+ end
439
+
420
440
  to_delete.each{|key| delete(key)}
441
+
421
442
  self
422
443
  end
423
444
 
data/map.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "map"
6
- spec.version = "6.4.0"
6
+ spec.version = "6.4.1"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
data/test/map_test.rb CHANGED
@@ -750,6 +750,16 @@ Testing Map do
750
750
  assert{ m.name_for(:A, :B, :C, :prefix => :foo) == 'foo[A][B][C]' }
751
751
  end
752
752
 
753
+ testing 'delete_if' do
754
+ m = Map.for(:k => :v)
755
+ assert{ m.delete_if{|k| k.to_s == 'k'} }
756
+ assert{ m.empty?}
757
+
758
+ m = Map.for(:k => :v)
759
+ assert{ m.delete_if{|k,v| v.to_s == 'v'} }
760
+ assert{ m.empty?}
761
+ end
762
+
753
763
  protected
754
764
  def new_int_map(n = 1024)
755
765
  map = assert{ Map.new }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: map
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.0
4
+ version: 6.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-18 00:00:00.000000000 Z
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'description: map kicks the ass'
15
15
  email: ara.t.howard@gmail.com