map 6.4.2 → 6.5.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.
data/README CHANGED
@@ -36,8 +36,8 @@ DESCRIPTION
36
36
  m[:b] = 1
37
37
  m[:c] = 2
38
38
 
39
- p m.keys #=> ['a','b','c'] ### always ordered!
40
- p m.keys #=> [0,1,2] ### always ordered!
39
+ p m.keys #=> ['a','b','c'] ### always ordered!
40
+ p m.values #=> [0,1,2] ### always ordered!
41
41
 
42
42
  # maps don't care about symbol vs.string keys
43
43
  #
data/Rakefile CHANGED
@@ -32,7 +32,7 @@ def run_tests!(which = nil)
32
32
 
33
33
  test_rbs.each_with_index do |test_rb, index|
34
34
  testno = index + 1
35
- command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
35
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
36
36
 
37
37
  puts
38
38
  say(div, :color => :cyan, :bold => true)
data/lib/map.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class Map < Hash
3
- Version = '6.4.2' unless defined?(Version)
3
+ Version = '6.5.0' unless defined?(Version)
4
4
  Load = Kernel.method(:load) unless defined?(Load)
5
5
 
6
6
  class << Map
@@ -56,6 +56,12 @@ class Map < Hash
56
56
  end
57
57
  end
58
58
 
59
+ def tap(*args, &block)
60
+ new(*args).tap do |map|
61
+ map.tap(&block) if block
62
+ end
63
+ end
64
+
59
65
  def conversion_methods
60
66
  @conversion_methods ||= (
61
67
  map_like = ancestors.select{|ancestor| ancestor <= Map}
@@ -104,7 +110,6 @@ class Map < Hash
104
110
  #
105
111
  def each_pair(*args, &block)
106
112
  size = args.size
107
- parity = size % 2 == 0 ? :even : :odd
108
113
  first = args.first
109
114
 
110
115
  if block.nil?
@@ -145,8 +150,8 @@ class Map < Hash
145
150
 
146
151
  if array_of_pairs
147
152
  args.each do |pair|
148
- key, val, *ignored = pair
149
- block.call(key, val)
153
+ k, v = pair[0..1]
154
+ block.call(k, v)
150
155
  end
151
156
  else
152
157
  0.step(args.size - 1, 2) do |a|
@@ -579,11 +584,15 @@ class Map < Hash
579
584
  end
580
585
 
581
586
  conversion_methods.each do |method|
582
- module_eval(<<-__, __FILE__, __LINE__)
583
- def #{ method }
584
- self
585
- end
586
- __
587
+ begin
588
+ instance_method(:to_map)
589
+ rescue NameError
590
+ module_eval(<<-__, __FILE__, __LINE__)
591
+ def #{ method }
592
+ self
593
+ end
594
+ __
595
+ end
587
596
  end
588
597
 
589
598
  def to_hash
@@ -696,7 +705,7 @@ class Map < Hash
696
705
  end
697
706
 
698
707
  if !Map.collection_has?(collection, key) && block_given?
699
- default_value = yield
708
+ yield #default_value
700
709
  else
701
710
  Map.collection_key(collection, key)
702
711
  end
@@ -833,11 +842,11 @@ class Map < Hash
833
842
  hash[key] = value
834
843
  end
835
844
 
836
- strategy = hash.map{|key, value| [Array(key), value]}
845
+ strategy = hash.map{|skey, svalue| [Array(skey), svalue]}
837
846
 
838
- strategy.each do |key, value|
839
- leaf_for(key, :autovivify => true) do |leaf, k|
840
- Map.collection_set(leaf, k, value)
847
+ strategy.each do |skey, svalue|
848
+ leaf_for(skey, :autovivify => true) do |leaf, k|
849
+ Map.collection_set(leaf, k, svalue)
841
850
  end
842
851
  end
843
852
 
@@ -859,12 +868,12 @@ class Map < Hash
859
868
 
860
869
  exploded = Map.explode(hash)
861
870
 
862
- exploded[:branches].each do |key, type|
863
- set(key, type.new) unless get(key).is_a?(type)
871
+ exploded[:branches].each do |bkey, btype|
872
+ set(bkey, btype.new) unless get(bkey).is_a?(btype)
864
873
  end
865
874
 
866
- exploded[:leaves].each do |key, value|
867
- set(key, value)
875
+ exploded[:leaves].each do |lkey, lvalue|
876
+ set(lkey, lvalue)
868
877
  end
869
878
 
870
879
  self
@@ -967,13 +976,13 @@ class Map < Hash
967
976
  paths, path = args.partition{|arg| arg.is_a?(Array)}
968
977
  paths.push(path)
969
978
 
970
- paths.each do |path|
971
- if path.size == 1
972
- delete(*path)
979
+ paths.each do |p|
980
+ if p.size == 1
981
+ delete(*p)
973
982
  next
974
983
  end
975
984
 
976
- branch, leaf = path[0..-2], path[-1]
985
+ branch, leaf = p[0..-2], p[-1]
977
986
  collection = get(branch)
978
987
 
979
988
  case collection
@@ -984,7 +993,7 @@ class Map < Hash
984
993
  index = leaf
985
994
  collection.delete_at(index)
986
995
  else
987
- raise(IndexError, "(#{ collection.inspect }).rm(#{ path.inspect })")
996
+ raise(IndexError, "(#{ collection.inspect }).rm(#{ p.inspect })")
988
997
  end
989
998
  end
990
999
  paths
@@ -1118,22 +1127,23 @@ class Map < Hash
1118
1127
 
1119
1128
  def Map.keys_for(enumerable)
1120
1129
  keys = enumerable.respond_to?(:keys) ? enumerable.keys : Array.new(enumerable.size){|i| i}
1130
+ keys
1121
1131
  end
1122
1132
 
1123
1133
  def depth_first_each(*args, &block)
1124
- Map.depth_first_each(enumerable=self, *args, &block)
1134
+ Map.depth_first_each(self, *args, &block)
1125
1135
  end
1126
1136
 
1127
1137
  def depth_first_keys(*args, &block)
1128
- Map.depth_first_keys(enumerable=self, *args, &block)
1138
+ Map.depth_first_keys(self, *args, &block)
1129
1139
  end
1130
1140
 
1131
1141
  def depth_first_values(*args, &block)
1132
- Map.depth_first_values(enumerable=self, *args, &block)
1142
+ Map.depth_first_values(self, *args, &block)
1133
1143
  end
1134
1144
 
1135
1145
  def breadth_first_each(*args, &block)
1136
- Map.breadth_first_each(enumerable=self, *args, &block)
1146
+ Map.breadth_first_each(self, *args, &block)
1137
1147
  end
1138
1148
 
1139
1149
  def contains(other)
data/lib/map/struct.rb CHANGED
@@ -43,7 +43,7 @@ class Map
43
43
  end
44
44
 
45
45
  def struct
46
- @struct ||= Struct.new(map=self)
46
+ @struct ||= Struct.new(self)
47
47
  end
48
48
 
49
49
  def Map.struct(*args, &block)
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 = "6.4.2"
6
+ spec.version = "6.5.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
data/test/lib/testing.rb CHANGED
@@ -34,7 +34,6 @@
34
34
  end
35
35
 
36
36
  def self.testing(*args, &block)
37
- method = ["test", testno, slug_for(*args)].delete_if{|part| part.empty?}.join('_')
38
37
  define_method("test_#{ testno }_#{ slug_for(*args) }", &block)
39
38
  end
40
39
 
@@ -69,7 +68,7 @@
69
68
  __assert_raises__(*args, &block)
70
69
  end
71
70
 
72
- module_eval &block
71
+ module_eval(&block)
73
72
  self
74
73
  end
75
74
  end
data/test/map_test.rb CHANGED
@@ -361,8 +361,8 @@ Testing Map do
361
361
  assert{ m[:x][:y].is_a?(Map) }
362
362
  assert{ m[:x][:y][:z] == 42.0 }
363
363
 
364
- assert{ Map.new.tap{|m| m.set} =~ {} }
365
- assert{ Map.new.tap{|m| m.set({})} =~ {} }
364
+ assert{ Map.new.tap{|nm| nm.set} =~ {} }
365
+ assert{ Map.new.tap{|nm| nm.set({})} =~ {} }
366
366
  end
367
367
 
368
368
  testing 'that Map#get supports providing a default value in a block' do
@@ -442,8 +442,8 @@ Testing Map do
442
442
  {"a"=>{"b"=>{"c"=>42, "d"=>42.0}}}
443
443
  end
444
444
 
445
- assert{ Map.new.tap{|m| m.add} =~ {} }
446
- assert{ Map.new.tap{|m| m.add({})} =~ {} }
445
+ assert{ Map.new.tap{|i| i.add} =~ {} }
446
+ assert{ Map.new.tap{|i| i.add({})} =~ {} }
447
447
  end
448
448
 
449
449
  testing 'that Map.combine is teh sweet' do
@@ -567,7 +567,6 @@ Testing Map do
567
567
 
568
568
  testing 'that maps with un-marshal-able objects can be copied' do
569
569
  open(__FILE__) do |f|
570
- f
571
570
  m = Map.for(:f => f)
572
571
  assert{ m.copy }
573
572
  assert{ m.dup }
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: 6.4.2
4
+ version: 6.5.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: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'description: map kicks the ass'
15
15
  email: ara.t.howard@gmail.com