map 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/a.rb +40 -3
  2. data/lib/map.rb +22 -7
  3. data/lib/map/options.rb +5 -0
  4. data/map.gemspec +1 -1
  5. metadata +4 -4
data/a.rb CHANGED
@@ -1,7 +1,44 @@
1
1
  require 'map'
2
2
 
3
- m = Map.new
3
+ #m = Map.new
4
+ #m.default = []
5
+
6
+ class Errors < ::Map
7
+ def [](key)
8
+ self[key] = Array.new unless has_key?(key)
9
+ super
10
+ end
11
+ end
4
12
 
5
- m.default = []
13
+ e = Errors.new
14
+ p e[:k]
15
+ p e
16
+ e.set(:a, :b, 42)
17
+ p e.get(:a, :b)
18
+ p e
19
+ #m = Map.new{|m,k| m[k] ||= Array.new}
20
+
21
+
22
+ #m.set(:a, :b, 42)
23
+ #p m.get(:a, :b)
24
+
25
+
26
+ #m[:a].push(:b)
27
+ #p m[:a]
28
+ #p m
29
+ #p m
30
+
31
+
32
+ __END__
33
+ args = [:a, :b, {:k => :v}]
34
+
35
+ Map.update_options_for!(args) do |options|
36
+ options[:foo] = :bar
37
+ end
38
+
39
+ Map.update_options_for!(args) do |options|
40
+ options[:time] = Time.now
41
+ end
42
+
43
+ p args
6
44
 
7
- m.get(:a, :b)
data/lib/map.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Map < Hash
2
- Version = '4.3.0' unless defined?(Version)
2
+ Version = '4.4.0' unless defined?(Version)
3
3
  Load = Kernel.method(:load) unless defined?(Load)
4
4
 
5
5
  class << Map
@@ -633,15 +633,22 @@ class Map < Hash
633
633
  if !self.has_key?(keys.first) && block_given?
634
634
  return yield
635
635
  else
636
- return self[keys.first]
636
+ return self[keys.first]
637
637
  end
638
638
  end
639
639
  keys, key = keys[0..-2], keys[-1]
640
640
  collection = self
641
641
  keys.each do |k|
642
642
  k = alphanumeric_key_for(k)
643
- collection = collection[k]
644
- return collection unless collection.respond_to?('[]')
643
+ if collection_has_key?(collection, k)
644
+ collection = collection[k]
645
+ else
646
+ collection = nil
647
+ end
648
+ unless collection.respond_to?('[]')
649
+ leaf = collection
650
+ return leaf
651
+ end
645
652
  end
646
653
  alphanumeric_key = alphanumeric_key_for(key)
647
654
 
@@ -659,7 +666,11 @@ class Map < Hash
659
666
  keys, key = keys[0..-2], keys[-1]
660
667
  keys.each do |k|
661
668
  k = alphanumeric_key_for(k)
662
- collection = collection[k]
669
+ if collection_has_key?(collection, k)
670
+ collection = collection[k]
671
+ else
672
+ collection = nil
673
+ end
663
674
  return collection unless collection.respond_to?('[]')
664
675
  end
665
676
  return false unless(collection.is_a?(Hash) or collection.is_a?(Array))
@@ -724,13 +735,17 @@ class Map < Hash
724
735
  keys.each_cons(2) do |a, b|
725
736
  a, b = alphanumeric_key_for(a), alphanumeric_key_for(b)
726
737
 
738
+ exists = collection_has_key?(collection, a)
739
+
727
740
  case b
728
741
  when Numeric
729
- collection[a] ||= []
742
+ #collection[a] ||= []
743
+ collection[a] = [] unless exists
730
744
  raise(IndexError, "(#{ collection.inspect })[#{ a.inspect }]=#{ value.inspect }") unless collection[a].is_a?(Array)
731
745
 
732
746
  when String, Symbol
733
- collection[a] ||= {}
747
+ #collection[a] ||= {}
748
+ collection[a] = {} unless exists
734
749
  raise(IndexError, "(#{ collection.inspect })[#{ a.inspect }]=#{ value.inspect }") unless collection[a].is_a?(Hash)
735
750
  end
736
751
  collection = collection[a]
data/lib/map/options.rb CHANGED
@@ -112,6 +112,10 @@ class Map
112
112
  defined?(@popped) and @popped
113
113
  end
114
114
 
115
+ def popped=(boolean)
116
+ @popped = !!boolean
117
+ end
118
+
115
119
  def pop!
116
120
  if arguments.last.is_a?(Hash)
117
121
  @popped = arguments.pop
@@ -155,6 +159,7 @@ def Map.update_options_for!(args, &block)
155
159
  block.call(options)
156
160
  ensure
157
161
  args.push(options)
162
+ options.popped = false
158
163
  end
159
164
 
160
165
  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.3.0"
6
+ spec.version = "4.4.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
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: 51
4
+ hash: 47
5
5
  prerelease:
6
6
  segments:
7
7
  - 4
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 4.3.0
10
+ version: 4.4.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-08-17 00:00:00 -06:00
18
+ date: 2011-08-21 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies: []
21
21