map 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/map.rb +5 -1
- data/test/map_test.rb +13 -1
- metadata +3 -3
data/lib/map.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Map < Hash
|
2
|
-
Version = '1.
|
2
|
+
Version = '1.2.0' unless defined?(Version)
|
3
3
|
Load = Kernel.method(:load) unless defined?(Load)
|
4
4
|
|
5
5
|
class << Map
|
@@ -332,6 +332,10 @@ class Map < Hash
|
|
332
332
|
super hash
|
333
333
|
end
|
334
334
|
|
335
|
+
def =~(hash)
|
336
|
+
to_hash == Map.for(hash).to_hash
|
337
|
+
end
|
338
|
+
|
335
339
|
def invert
|
336
340
|
inverted = Map.new
|
337
341
|
inverted.default = self.default
|
data/test/map_test.rb
CHANGED
@@ -154,12 +154,24 @@ Testing Map do
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
+
testing 'the match operator, which can make testing hash equality simpler!' do
|
158
|
+
map = new_int_map
|
159
|
+
hash = new_int_hash
|
160
|
+
assert{ map =~ hash }
|
161
|
+
end
|
162
|
+
|
157
163
|
protected
|
158
164
|
def new_int_map(n = 1024)
|
159
|
-
map = Map.new
|
165
|
+
map = assert{ Map.new }
|
160
166
|
n.times{|i| map[i.to_s] = i}
|
161
167
|
map
|
162
168
|
end
|
169
|
+
|
170
|
+
def new_int_hash(n = 1024)
|
171
|
+
hash = Hash.new
|
172
|
+
n.times{|i| hash[i.to_s] = i}
|
173
|
+
hash
|
174
|
+
end
|
163
175
|
end
|
164
176
|
|
165
177
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ara T. Howard
|