map 2.9.1 → 3.0.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 +21 -19
  2. data/map.gemspec +1 -1
  3. data/test/map_test.rb +5 -5
  4. metadata +6 -6
data/lib/map.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Map < Hash
2
- Version = '2.9.1' unless defined?(Version)
2
+ Version = '3.0.0' unless defined?(Version)
3
3
  Load = Kernel.method(:load) unless defined?(Load)
4
4
 
5
5
  class << Map
@@ -63,11 +63,13 @@ class Map < Hash
63
63
  next if name.empty?
64
64
  name.downcase.gsub(/::/, '_')
65
65
  end.compact
66
- type_names.map{|type_name| "to_#{ type_name }"}
66
+ list = type_names.map{|type_name| "to_#{ type_name }"}
67
+ list.each{|method| define_conversion_method!(method)}
68
+ list
67
69
  )
68
70
  end
69
71
 
70
- def add_conversion_method!(method)
72
+ def define_conversion_method!(method)
71
73
  method = method.to_s.strip
72
74
  raise ArguementError if method.empty?
73
75
  module_eval(<<-__, __FILE__, __LINE__)
@@ -75,16 +77,26 @@ class Map < Hash
75
77
  def #{ method }
76
78
  self
77
79
  end
78
- end
79
- unless conversion_methods.include?(#{ method.inspect })
80
- conversion_methods.unshift(#{ method.inspect })
80
+ true
81
+ else
82
+ false
81
83
  end
82
84
  __
83
85
  end
84
86
 
85
- def inherited(other)
86
- other.module_eval(&Dynamic)
87
- super
87
+ def add_conversion_method!(method)
88
+ if define_conversion_method!(method)
89
+ method = method.to_s.strip
90
+ raise ArguementError if method.empty?
91
+ module_eval(<<-__, __FILE__, __LINE__)
92
+ unless conversion_methods.include?(#{ method.inspect })
93
+ conversion_methods.unshift(#{ method.inspect })
94
+ end
95
+ __
96
+ true
97
+ else
98
+ false
99
+ end
88
100
  end
89
101
 
90
102
  # iterate over arguments in pairs smartly.
@@ -158,16 +170,6 @@ class Map < Hash
158
170
  end
159
171
  end
160
172
 
161
- unless defined?(Dynamic)
162
- Dynamic = lambda do
163
- conversion_methods.reverse_each do |method|
164
- add_conversion_method!(method)
165
- end
166
- end
167
- module_eval(&Dynamic)
168
- end
169
-
170
-
171
173
  # instance constructor
172
174
  #
173
175
  def keys
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "map"
6
- spec.version = "2.9.1"
6
+ spec.version = "3.0.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
@@ -284,15 +284,15 @@ Testing Map do
284
284
 
285
285
  testing 'that method missing hacks allow setting values, but not getting them until they are set' do
286
286
  m = Map.new
287
- assert{ (m.key rescue $!).is_a?(Exception) }
288
- assert{ m.key = :val }
289
- assert{ m[:key] == :val }
290
- assert{ m.key == :val }
287
+ assert{ (m.missing rescue $!).is_a?(Exception) }
288
+ assert{ m.missing = :val }
289
+ assert{ m[:missing] == :val }
290
+ assert{ m.missing == :val }
291
291
  end
292
292
 
293
293
  testing 'that method missing with a block delegatets to fetch' do
294
294
  m = Map.new
295
- assert{ m.key{ :val } == :val }
295
+ assert{ m.missing{ :val } == :val }
296
296
  assert{ !m.has_key?(:key) }
297
297
  end
298
298
 
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: 41
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
- - 2
8
- - 9
9
- - 1
10
- version: 2.9.1
7
+ - 3
8
+ - 0
9
+ - 0
10
+ version: 3.0.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: 2011-04-18 00:00:00 -06:00
18
+ date: 2011-04-21 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies: []
21
21