orderedhash / 1.2005.8.16
| Short description: | Hash with preserved order (like Array in php) | |||||
|---|---|---|---|---|---|---|
| Category: | Library/Datastructure | |||||
| Status: | stable | |||||
| Created: | 2004-09-17 16:37:45 GMT | |||||
| Last update: | 2005-08-16 14:06:04 GMT | |||||
| Owner: | Jan Molič (Projects of this owner) | |||||
| Homepage: | http://simplypowerful.1984.cz/orderedhash/1.2005.8.16/doc/ | |||||
| Download: | http://simplypowerful.1984.cz/orderedhash/1.2005.8.16/orderedhash.tgz | |||||
| License: | Ruby's | |||||
| Dependency: |
|
|||||
| Description: |
# You can simply do
hsh = OrderedHash.new
hsh['z'] = 1
hsh['a'] = 2
hsh['c'] = 3
p hsh.keys # ['z','a','c']
# or using OrderedHash[] method
hsh = OrderedHash['z', 1, 'a', 2, 'c', 3]
p hsh.keys # ['z','a','c']
# OrderedHash has useful extensions: push, pop and unshift
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
|
|||||
| Versions: | [1.2006.07.13 (2007-07-05)] [1.2006.05.23 (2006-05-25)] [1.2005.8.16 (2005-08-16)] [1.2005.8.8 (2005-08-15)] [2.0 (2004-12-07)] [2.0-rc1 (2004-11-19)] [1.1 (2004-11-19)] [1.0-r5 (2004-10-11)] [1.0-r4 (2004-10-07)] [0.1 (2004-09-17)] | |||||