map 4.7.1 → 5.1.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.
Files changed (6) hide show
  1. data/a.rb +22 -16
  2. data/lib/map.rb +2 -2
  3. data/lib/map/options.rb +16 -24
  4. data/map.gemspec +1 -1
  5. data/test/map_test.rb +4 -0
  6. metadata +3 -3
data/a.rb CHANGED
@@ -1,24 +1,30 @@
1
1
  require 'map'
2
2
 
3
+ args = [0, 1, {:k => :v, :a => false}]
4
+ opts = Map.options_for!(args)
3
5
 
4
- require 'rubygems'
5
- require 'mongoid'
6
+ #p args.object_id
7
+ #p opts.arguments.object_id
8
+ #p !args.last.is_a?(Hash)
9
+ #puts
10
+ #puts
6
11
 
7
- class Map
8
- include Mongoid::Fields::Serializable
12
+ new_args = [0, 1, opts]
13
+ new_opts = Map.options_for!(new_args)
14
+ #p new_opts.popped?
15
+ p new_args
16
+ p args
17
+ #p !new_args.last.is_a?(Hash)
18
+ #p new_opts.arguments.object_id
19
+ #p new_args.object_id
9
20
 
10
- def default(*args)
11
- @default
12
- end
21
+ puts
22
+ puts
23
+ __END__
13
24
 
14
- def deserialize(object)
15
- Map.for(object.to_hash)
16
- end
25
+ puts '---'
26
+
27
+ p opts.arguments
28
+ p args
17
29
 
18
- def serialize(object)
19
- object.to_hash
20
- end
21
- end
22
30
 
23
- m = Map.new
24
- m[:key]
data/lib/map.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Map < Hash
2
- Version = '4.7.1' unless defined?(Version)
2
+ Version = '5.1.0' unless defined?(Version)
3
3
  Load = Kernel.method(:load) unless defined?(Load)
4
4
 
5
5
  class << Map
@@ -617,7 +617,7 @@ class Map < Hash
617
617
  else
618
618
  key = method
619
619
  unless has_key?(key)
620
- return(block ? fetch(*args, &block) : super(*args))
620
+ return(block ? fetch(key, &block) : super(*args))
621
621
  end
622
622
  self[key]
623
623
  end
data/lib/map/options.rb CHANGED
@@ -2,7 +2,7 @@ class Map
2
2
  module Options
3
3
  class << Options
4
4
  def for(arg)
5
- hash =
5
+ options =
6
6
  case arg
7
7
  when Hash
8
8
  arg
@@ -14,18 +14,19 @@ class Map
14
14
  raise(ArgumentError, arg.inspect) unless arg.respond_to?(:to_hash)
15
15
  arg.to_hash
16
16
  end
17
- map = Map.coerce(hash)
18
- ensure
19
- map.extend(Options) unless map.is_a?(Options)
17
+ options.extend(Options) unless options.is_a?(Options)
18
+ options
20
19
  end
21
20
 
22
21
  def parse(arg)
23
22
  case arg
24
23
  when Array
25
- arg.extend(Arguments) unless arg.is_a?(Arguments)
26
- arg.options
24
+ arguments = arg
25
+ arguments.extend(Arguments) unless arguments.is_a?(Arguments)
26
+ options = arguments.options
27
27
  when Hash
28
- Options.for(arg)
28
+ options = arg
29
+ options = Options.for(options)
29
30
  else
30
31
  raise(ArgumentError, "`arg` should be an Array or Hash")
31
32
  end
@@ -109,27 +110,21 @@ class Map
109
110
  end
110
111
 
111
112
  def popped?
112
- defined?(@popped) and @popped
113
- end
114
-
115
- def popped=(boolean)
116
- @popped = !!boolean
113
+ arguments and arguments.last != self
117
114
  end
118
115
 
119
116
  def pop!
120
- if arguments.last.is_a?(Hash)
121
- @popped = arguments.pop
122
- else
123
- @popped = true
124
- end
117
+ arguments.pop if !popped?
125
118
  end
126
119
  end
127
120
 
128
121
  module Arguments
129
122
  def options
130
- @options ||= Options.for(last.is_a?(Hash) ? last : {})
131
- ensure
132
- @options.arguments = self
123
+ @options ||=(
124
+ options = Options.for(last.is_a?(Hash) ? last : {})
125
+ options.arguments = self
126
+ options
127
+ )
133
128
  end
134
129
 
135
130
  class << Arguments
@@ -155,11 +150,8 @@ def Map.options_for!(*args, &block)
155
150
  end
156
151
 
157
152
  def Map.update_options_for!(args, &block)
158
- options = Map.options_for!(args)
153
+ options = Map.options_for(args)
159
154
  block.call(options)
160
- ensure
161
- args.push(options)
162
- options.popped = false
163
155
  end
164
156
 
165
157
  class << Map
data/map.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "map"
6
- spec.version = "4.7.1"
6
+ spec.version = "5.1.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
data/test/map_test.rb CHANGED
@@ -282,6 +282,10 @@ Testing Map do
282
282
  args = [0,1, {:k => :v, :a => false}]
283
283
  opts = assert{ Map.send(method, args) }
284
284
  assert{ !args.last.is_a?(Hash) }
285
+
286
+ new_args = [0,1, opts]
287
+ new_opts = assert{ Map.send(method, new_args) }
288
+ assert{ !new_args.last.is_a?(Hash) }
285
289
  end
286
290
  end
287
291
 
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: 4.7.1
4
+ version: 5.1.0
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: 2011-10-24 00:00:00.000000000 Z
12
+ date: 2011-12-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'description: map kicks the ass'
15
15
  email: ara.t.howard@gmail.com
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  requirements: []
51
51
  rubyforge_project: codeforpeople
52
- rubygems_version: 1.8.10
52
+ rubygems_version: 1.8.11
53
53
  signing_key:
54
54
  specification_version: 3
55
55
  summary: map