map 6.4.0 → 6.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/map.rb +24 -3
- data/map.gemspec +1 -1
- data/test/map_test.rb +10 -0
- 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.
|
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
|
-
|
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
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.
|
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-
|
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
|