map 1.5.1 → 1.6.0

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 +1 -1
  2. data/lib/map/options.rb +15 -3
  3. data/test/map_test.rb +20 -1
  4. metadata +7 -4
data/lib/map.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Map < Hash
2
- Version = '1.5.1' unless defined?(Version)
2
+ Version = '1.6.0' unless defined?(Version)
3
3
  Load = Kernel.method(:load) unless defined?(Load)
4
4
 
5
5
  class << Map
@@ -142,10 +142,22 @@ class Map
142
142
  end
143
143
 
144
144
 
145
- def Map.options(*args, &block)
145
+ def Map.options_for(*args, &block)
146
146
  Map::Options.for(*args, &block)
147
147
  end
148
148
 
149
- def Map.opts(*args, &block)
150
- Map::Options.for(*args, &block)
149
+ def Map.options_for!(*args, &block)
150
+ Map::Options.for(*args, &block).pop
151
+ end
152
+
153
+ class << Map
154
+ src = 'options_for'
155
+ %w( options opts ).each do |dst|
156
+ alias_method(dst, src)
157
+ end
158
+
159
+ src = 'options_for!'
160
+ %w( options! opts! ).each do |dst|
161
+ alias_method(dst, src)
162
+ end
151
163
  end
@@ -187,13 +187,32 @@ Testing Map do
187
187
  assert{ s.k.l == :v }
188
188
  end
189
189
 
190
- testing 'that subclassing and clobbering initialize does not kill nested coercion' do
190
+ testing 'that subclassing and clobbering initialize does not kill nested coersion' do
191
191
  c = Class.new(Map){ def initialize(arg) end }
192
192
  o = assert{ c.new(42) }
193
193
  assert{ Map === o }
194
194
  assert{ o.update(:k => {:a => :b}) }
195
195
  end
196
196
 
197
+ testing 'that map supports basic option parsing for methods' do
198
+ %w( options_for options opts ).each do |method|
199
+ args = [0,1, {:k => :v, :a => false}]
200
+ opts = assert{ Map.send(method, args) }
201
+ assert{ opts.getopt(:k)==:v }
202
+ assert{ opts.getopt(:a)==false }
203
+ assert{ opts.getopt(:b, :default => 42)==42 }
204
+ assert{ args.last.is_a?(Hash) }
205
+ end
206
+ end
207
+
208
+ testing 'that bang option parsing can pop the options off' do
209
+ %w( options_for! options! opts! ).each do |method|
210
+ args = [0,1, {:k => :v, :a => false}]
211
+ opts = assert{ Map.send(method, args) }
212
+ assert{ !args.last.is_a?(Hash) }
213
+ end
214
+ end
215
+
197
216
  protected
198
217
  def new_int_map(n = 1024)
199
218
  map = assert{ Map.new }
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: map
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 5
8
- - 1
9
- version: 1.5.1
8
+ - 6
9
+ - 0
10
+ version: 1.6.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ara T. Howard
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-28 00:00:00 -06:00
18
+ date: 2010-11-17 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -50,6 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - ">="
52
53
  - !ruby/object:Gem::Version
54
+ hash: 3
53
55
  segments:
54
56
  - 0
55
57
  version: "0"
@@ -58,6 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
60
  requirements:
59
61
  - - ">="
60
62
  - !ruby/object:Gem::Version
63
+ hash: 3
61
64
  segments:
62
65
  - 0
63
66
  version: "0"