Permalink
Browse files

Merge pull request #19 from copiousfreetime/bufix/ruby19-warnings

Make Map ruby 1.9 -w clean.
  • Loading branch information...
2 parents 8deb334 + 5ad387b commit 13595e8f4e56a0902eda8652a02cee662fec92e0 @ahoward committed Apr 22, 2013
Showing with 27 additions and 30 deletions.
  1. +1 −1 Rakefile
  2. +20 −21 lib/map.rb
  3. +1 −1 lib/map/struct.rb
  4. +1 −2 test/lib/testing.rb
  5. +4 −5 test/map_test.rb
View
@@ -32,7 +32,7 @@ def run_tests!(which = nil)
test_rbs.each_with_index do |test_rb, index|
testno = index + 1
- command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
puts
say(div, :color => :cyan, :bold => true)
View
@@ -104,7 +104,6 @@ def add_conversion_method!(method)
#
def each_pair(*args, &block)
size = args.size
- parity = size % 2 == 0 ? :even : :odd
first = args.first
if block.nil?
@@ -145,8 +144,8 @@ def each_pair(*args, &block)
if array_of_pairs
args.each do |pair|
- key, val, *ignored = pair
- block.call(key, val)
+ k, v = pair[0..1]
+ block.call(k, v)
end
else
0.step(args.size - 1, 2) do |a|
@@ -696,7 +695,7 @@ def get(*keys)
end
if !Map.collection_has?(collection, key) && block_given?
- default_value = yield
+ yield #default_value
else
Map.collection_key(collection, key)
end
@@ -833,11 +832,11 @@ def set(*args)
hash[key] = value
end
- strategy = hash.map{|key, value| [Array(key), value]}
+ strategy = hash.map{|skey, svalue| [Array(skey), svalue]}
- strategy.each do |key, value|
- leaf_for(key, :autovivify => true) do |leaf, k|
- Map.collection_set(leaf, k, value)
+ strategy.each do |skey, svalue|
+ leaf_for(skey, :autovivify => true) do |leaf, k|
+ Map.collection_set(leaf, k, svalue)
end
end
@@ -859,12 +858,12 @@ def add(*args)
exploded = Map.explode(hash)
- exploded[:branches].each do |key, type|
- set(key, type.new) unless get(key).is_a?(type)
+ exploded[:branches].each do |bkey, btype|
+ set(bkey, btype.new) unless get(bkey).is_a?(btype)
end
- exploded[:leaves].each do |key, value|
- set(key, value)
+ exploded[:leaves].each do |lkey, lvalue|
+ set(lkey, lvalue)
end
self
@@ -967,13 +966,13 @@ def rm(*args)
paths, path = args.partition{|arg| arg.is_a?(Array)}
paths.push(path)
- paths.each do |path|
- if path.size == 1
- delete(*path)
+ paths.each do |p|
+ if p.size == 1
+ delete(*p)
next
end
- branch, leaf = path[0..-2], path[-1]
+ branch, leaf = p[0..-2], p[-1]
collection = get(branch)
case collection
@@ -984,7 +983,7 @@ def rm(*args)
index = leaf
collection.delete_at(index)
else
- raise(IndexError, "(#{ collection.inspect }).rm(#{ path.inspect })")
+ raise(IndexError, "(#{ collection.inspect }).rm(#{ p.inspect })")
end
end
paths
@@ -1121,19 +1120,19 @@ def Map.keys_for(enumerable)
end
def depth_first_each(*args, &block)
- Map.depth_first_each(enumerable=self, *args, &block)
+ Map.depth_first_each(self, *args, &block)
end
def depth_first_keys(*args, &block)
- Map.depth_first_keys(enumerable=self, *args, &block)
+ Map.depth_first_keys(self, *args, &block)
end
def depth_first_values(*args, &block)
- Map.depth_first_values(enumerable=self, *args, &block)
+ Map.depth_first_values(self, *args, &block)
end
def breadth_first_each(*args, &block)
- Map.breadth_first_each(enumerable=self, *args, &block)
+ Map.breadth_first_each(self, *args, &block)
end
def contains(other)
View
@@ -43,7 +43,7 @@ def #{ delegate }(*args, &block)
end
def struct
- @struct ||= Struct.new(map=self)
+ @struct ||= Struct.new(self)
end
def Map.struct(*args, &block)
View
@@ -34,7 +34,6 @@ def self.testno()
end
def self.testing(*args, &block)
- method = ["test", testno, slug_for(*args)].delete_if{|part| part.empty?}.join('_')
define_method("test_#{ testno }_#{ slug_for(*args) }", &block)
end
@@ -69,7 +68,7 @@ def assert_raises(*args, &block)
__assert_raises__(*args, &block)
end
- module_eval &block
+ module_eval(&block)
self
end
end
View
@@ -361,8 +361,8 @@ def to_map() {:k => :b} end
assert{ m[:x][:y].is_a?(Map) }
assert{ m[:x][:y][:z] == 42.0 }
- assert{ Map.new.tap{|m| m.set} =~ {} }
- assert{ Map.new.tap{|m| m.set({})} =~ {} }
+ assert{ Map.new.tap{|nm| nm.set} =~ {} }
+ assert{ Map.new.tap{|nm| nm.set({})} =~ {} }
end
testing 'that Map#get supports providing a default value in a block' do
@@ -442,8 +442,8 @@ def to_map() {:k => :b} end
{"a"=>{"b"=>{"c"=>42, "d"=>42.0}}}
end
- assert{ Map.new.tap{|m| m.add} =~ {} }
- assert{ Map.new.tap{|m| m.add({})} =~ {} }
+ assert{ Map.new.tap{|i| i.add} =~ {} }
+ assert{ Map.new.tap{|i| i.add({})} =~ {} }
end
testing 'that Map.combine is teh sweet' do
@@ -567,7 +567,6 @@ def o.to_map() {:k => :v} end
testing 'that maps with un-marshal-able objects can be copied' do
open(__FILE__) do |f|
- f
m = Map.for(:f => f)
assert{ m.copy }
assert{ m.dup }

0 comments on commit 13595e8

Please sign in to comment.