matthew.moss.coder
3/13/2006 1:45:00 AM
(On Mac OS X 10.4.5, Ruby 1.8.4)
Okay, so:
> [1, 2, 3].inject(0) { |s, v| s += v }
=> 6
and:
> [1, 2, 3].inject([]) { |a, v| a << v**2 }
=> [1, 4, 9]
but:
> [1, 2, 3].inject({}) { |h, v| h[v] = v**2 }
=> NoMethodError: undefined method `[]=' for 1:Fixnum
What gives?
I've tried replacing {} with Hash.new and a couple other variants without luck.