From: Brian Candler Date: 2010-06-23T19:03:22+09:00 Subject: Re: Iterate over specific keys in a hash Update: if you are interested at the values for particular keys, then you can also do >> cars = { "car0" => "bmw", "car1" => "seat", "car3" => "mercedes", "car4" => "renault"} >> cars.values_at("car0","car3").each { |c| puts c } bmw mercedes => ["bmw", "mercedes"] If you really want to rely on the insertion order, which I'd strongly recommend against even under ruby 1.9, there's a brute-force way: cars.each_value.with_index do |c,i| next unless [0,3].include?(i) puts c end Note that this will give you bmw and renault, because it ignores the keys completely. -- Posted via http://www.ruby-forum.com/.