I
Iain Barnett
Since hashes in 1.9 retain their insert order, is there a built in way =
to get values by index as well as key?
For example:
h =3D { a: 17, b: 18, c: 19 }
puts h[1]
=3D> 19
Obviously that can't work, but there may be some other way I haven't =
found by looking through the docs? At the moment I'm using this:
class Hash
def by_index( n )
self.each_with_index { |item, index| break item if index =3D=3D n =
}
end
end
Just wondering.
Regards,
Iain
to get values by index as well as key?
For example:
h =3D { a: 17, b: 18, c: 19 }
puts h[1]
=3D> 19
Obviously that can't work, but there may be some other way I haven't =
found by looking through the docs? At the moment I'm using this:
class Hash
def by_index( n )
self.each_with_index { |item, index| break item if index =3D=3D n =
}
end
end
Just wondering.
Regards,
Iain