Botp, thanks. That is an easier way to look at it. Can I go back to this
Enumerable#inject? I understand iterating on elements of an array like
this:
range = (1..4)
sum = range.inject(0) {|result, element| result += element }
#I understand inject to be doing this (where my 'i' means 'iteration'):
#sum(i=1) = 0 + 1 = 1
#sum(i=2) = sum(i=1) + 2 = 3
#sum(i=3) = sum(i=2) + 3 = 6
#sum(i=4) = sum(i=3) + 4 = 10
=> sum = 10
#However, iterating over a hash is confusing me. Here is a simple
example:
hash = [[:diameter, 45], [:id, 2]].inject({}) do |result, element|
result[element.first] = element.last
result
end
#can someone help me understand better what exactly is happening on each
iteration?
#hash(i=1) = ??
#hash(i=2) = ??
Thank you!
--
Posted via http://www.ruby-forum.com/.