map 1.6.0 → 1.7.0

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/map.rb +3 -4
  2. data/test/map_test.rb +11 -1
  3. metadata +4 -4
data/lib/map.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Map < Hash
2
- Version = '1.6.0' unless defined?(Version)
2
+ Version = '1.7.0' unless defined?(Version)
3
3
  Load = Kernel.method(:load) unless defined?(Load)
4
4
 
5
5
  class << Map
@@ -40,15 +40,14 @@ class Map < Hash
40
40
  end
41
41
 
42
42
  def for(*args, &block)
43
- first = args.first
44
43
  if(args.size == 1 and block.nil?)
45
- return first.to_map if first.respond_to?(:to_map)
44
+ return args.first if args.first.class == self
46
45
  end
47
46
  new(*args, &block)
48
47
  end
49
48
 
50
49
  def coerce(other)
51
- return other.to_map if other.respond_to?(:to_map)
50
+ return other if other.class == self
52
51
  allocate.update(other.to_hash)
53
52
  end
54
53
 
@@ -190,10 +190,20 @@ Testing Map do
190
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
- assert{ Map === o }
193
+ assert{ o.is_a?(c) }
194
194
  assert{ o.update(:k => {:a => :b}) }
195
195
  end
196
196
 
197
+ testing 'that subclassing does not kill class level coersion' do
198
+ c = Class.new(Map){ }
199
+ o = assert{ c.for(Map.new) }
200
+ assert{ o.is_a?(c) }
201
+
202
+ d = Class.new(c)
203
+ o = assert{ d.for(Map.new) }
204
+ assert{ o.is_a?(d) }
205
+ end
206
+
197
207
  testing 'that map supports basic option parsing for methods' do
198
208
  %w( options_for options opts ).each do |method|
199
209
  args = [0,1, {:k => :v, :a => false}]
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: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 1.6.0
10
+ version: 1.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ara T. Howard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-17 00:00:00 -07:00
18
+ date: 2010-12-23 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21