RAA - orderedhash

orderedhash / 1.2006.07.13

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: 2007-07-05 11:46:46 GMT
Owner: Jan Molič (Projects of this owner)
Homepage: http://facets.rubyforge.org
Download: http://facets.rubyforge.org
License: Ruby's
Dependency:
None
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
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)]

Edit this project (for project owner)

back to RAA top