This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Iterating Over a Hash in Insertion Order | ||
---|---|---|

Code | Expected | Actual |

require 'orderedhash' h = OrderedHash.new h[1] = 1 h["second"] = 2 h[:third] = 3 h.keys |
[1, "second", :third] | [1, "second", :third] |

h.values |
[1, 2, 3] | [1, 2, 3] |

h.each { |k,v| puts "The #{k} counting number is #{v}" } |
The 1 counting number is 1 The second counting number is 2 The third counting number is 3 |
The 1 counting number is 1 The second counting number is 2 The third counting number is 3 |