| Description: |
Preserve items order like Array but it is still Hash.
You can use array-like methods, too, for example push, pop, shift, unshift, etc.
BUT: OrderedHash is now obsolete, use "Dictionary" from Ruby Facets instead. You don't know what Ruby Facets are? You must try them!
Usage:
1. gem install facets
2.
require 'rubygems'
require 'dictionary'
# You can simply do
hsh = Dictionary.new
hsh['z'] = 1
hsh['a'] = 2
hsh['c'] = 3
p hsh.keys # ['z','a','c']
p hsh.push('to_end', 15) # true, key added
p hsh.push('to_end', 30) # false, already - nothing happen
p hsh.unshift('to_begin', 50) # true, key added
p hsh.unshift('to_begin', 60) # false, already - nothing happen
p hsh.keys # ["to_begin", "a", "c", "z", "to_end"]
p hsh.pop # ["to_end", 15], if nothing remains, return nil
p hsh.keys # ["to_begin", "a", "c", "z"]
p hsh.shift # ["to_begin", 30], if nothing remains, return nil
|