I am looking in Ruby 1.8.6 docs, and there is no mentioning of each_with_index there.
But if I start up Ruby 1.8.7 or 1.9.2 and run the following, it works:
h = {:a => 1, :b => 2.2}
h.each_with_index do |pair, i|
p pair, i
end
Where does each_with_index come from? Hash.superclasss is Object, and Object doesn’t implement this instance method.
It comes from Enumerable, a module that’s mixed in into Hash.
Do
Hash.ancestorsto find mention of Enumerable.