Class Ramaze::Dictionary
In: lib/ramaze/snippets/ramaze/dictionary.rb
Parent: Object

Methods

<<   ==   []   []   []=   alpha   auto   clear   delete   delete_if   dup   each   each_key   each_pair   each_value   empty?   fetch   find   first   insert   inspect   invert   keys   last   length   merge   merge!   new   new_by   order   order_by   order_by_key   order_by_value   pop   push   reject   reject!   reorder   replace   select   shift   size   store   to_a   to_s   unshift   update   values  

Public Class methods

Alternate to new which creates a dictionary sorted by key.

  d = Dictionary.alpha
  d["z"] = 1
  d["y"] = 2
  d["x"] = 3
  d  #=> {"x"=>3,"y"=>2,"z"=>2}

This is equivalent to:

  Dictionary.new.order_by { |key,value| key }

Alternate to new which auto-creates sub-dictionaries as needed.

  d = Dictionary.auto
  d["a"]["b"]["c"] = "abc"  #=> { "a"=>{"b"=>{"c"=>"abc"}}}

Like new but the block sets the order.

Public Instance methods

def ==( hsh2 )

  return false if @order != hsh2.order
  super hsh2

end

Store operator.

  h[key] = value

Or with additional index.

 h[key,index] = value
each_pair()

Alias for each

merge!( hsh2 )

Alias for update

Keep dictionary sorted by a specific sort order.

Keep dictionary sorted by key.

  d = Dictionary.new.order_by_key
  d["z"] = 1
  d["y"] = 2
  d["x"] = 3
  d  #=> {"x"=>3,"y"=>2,"z"=>2}

This is equivalent to:

  Dictionary.new.order_by { |key,value| key }

The initializer Dictionary#alpha also provides this.

Keep dictionary sorted by value.

  d = Dictionary.new.order_by_value
  d["z"] = 1
  d["y"] = 2
  d["x"] = 3
  d  #=> {"x"=>3,"y"=>2,"z"=>2}

This is equivalent to:

  Dictionary.new.order_by { |key,value| value }
size()

Alias for length

[Validate]