Thanks everyone.

Btw, there is some very important information in
Programming Ruby -> 
More about Methods -> Making Blocks More Dynamic.

-
nord

#!/bin/ruby

class MyHash < Hash
  def initialize 
    # a Hash of (Hashes whose initial values read 0)
    super {|h,j| h[j] = Hash.new {0} }
  end

  def printSortedBy(sortOn='keys')
    puts "---- sorted by #{sortOn}"
    self.keys.sort.each do | m |
      puts m
      sortProc = {}
      sortProc['keys'] = proc {|a| a }
      sortProc['vals'] = proc {|a| -self[m][a] }
      self[m].keys.sort_by(&sortProc[sortOn]).each do
| k |
        puts "#{k.rjust(12)}
#{self[m][k].to_s.rjust(4)}"
      end
    end
  end
  private :printSortedBy

  def printByKeys
    printSortedBy('keys')
  end

  def printByVals
    printSortedBy('vals')
  end
end

metaData = MyHash.new
metaData['fruit']['apple'] = 13
metaData['fruit']['mango'] = 7
metaData['fruit']['banana'] = 11
metaData['fruit']['cherry'] = 17
metaData['veg']['eggplant'] = 7
metaData['veg']['artichoke'] += 19
metaData['veg']['green bean'] -= 5
metaData['veg']['squash'] += 2
metaData.printByKeys
metaData.printByVals



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com