Permalink
Browse files

fix update! argument order

  • Loading branch information...
1 parent 800b3ae commit 54c3eeeb420ba37a342df07c2ac6e148e4396ea4 @ninjudd committed Sep 17, 2011
Showing with 7 additions and 7 deletions.
  1. +4 −4 lib/rupture/map.rb
  2. +1 −1 lib/rupture/sequence.rb
  3. +2 −2 test/map_test.rb
View
@@ -7,12 +7,12 @@ def assoc!(*vals)
end
def update!(*args, &block)
- if args.size == 1
- key = args.shift
+ key = args.shift
+
+ if args.size == 0
self[key] = yield(self[key])
else
- fn = args.shift
- key = args.shift
+ fn = args.shift
self[key] = fn.call(self[key], *args, &block)
end
self
View
@@ -291,7 +291,7 @@ def sort_by(f = nil, &fn)
def frequencies
reduce({}) do |counts, x|
- counts.update!(:inc.fnil(0), x)
+ counts.update!(x, :inc.fnil(0))
end
end
View
@@ -16,11 +16,11 @@ class MapTest < Test::Unit::TestCase
should "update!" do
h = {:foo => 1, :bar => [1,2,3].seq}
- h.update!(:inc, :foo)
+ h.update!(:foo, :inc)
assert_equal({:foo => 2, :bar => [1,2,3].seq}, h)
- h.update!(:map, :bar) {|i| i + 10}
+ h.update!(:bar, :map) {|i| i + 10}
assert_equal({:foo => 2, :bar => [11,12,13].seq}, h)
h.update!(:foo) {|i| i + 10}

0 comments on commit 54c3eee

Please sign in to comment.