An iterator is an object that allows a programmer to traverse through
all the elements of a collection, regardless of its specific
implementation.

In object-oriented programming, the Iterator pattern is a design
pattern in which iterators are used to access the elements of an
aggregate object sequentially without exposing its underlying
representation.

So the order in which you can access the elements in the collection is
predefined by the underlying implementation. It is only guaranteed
that elements can not be skipped or that a previously visited element
can not be accessed a second time. But the order differs because of
different implementation.


2010/3/10 Dhananjay Bhavsar <dhananjaybhavsar / gmail.com>:
> Hello
> =A0the code is like this
> hash_fruit =3D {}
> hash_fruit ['mango']=3D'orange'
> hash_fruit ['banana']=3D'yellow'
> hash_fruit ['grapes']=3D'green'
> hash_fruit ['apple'] =3D 'red'
> hash_fruit .each do |key , value |
> puts key + ' =A0'+value
> =A0end
>
> and the answer is
> apple red
> banana yellow
> mango orange
> grapes green
>
> why is it so?
> --
> Posted via http://www.ruby-forum.com/.
>
>