class Hash def get_value(key) return Hash.get_hash_value(self,key) end def set_value(key,value) Hash.set_hash_value(self,key,value) end def self.get_hash_value(hash,key) return hash[key] if(hash.has_key?(key)) if key.kind_of?(String) if key.include?(',') keys=key.split(',') value=get_hash_value(hash,keys.shift) unless value.nil? if value.kind_of?(Hash) return Hash.get_hash_value(value,keys.join(',')) end end else value=nil ruby="value=hash[:#{key}]" eval(ruby) return value end end nil end def self.set_hash_value(hash,key,value) if key.kind_of?(String) if key.include?(',') keys=key.split(',') hval=get_hash_value(hash,keys[0]) if(hval.nil?) ruby="hash[:#{keys[0]}]=Hash.new" eval(ruby) end hval=get_hash_value(hash,keys[0]) if hval.kind_of?(Hash) keys.shift if keys.length == 1 Hash.set_hash_value(hval,keys[0],value) else Hash.set_hash_value(hval,keys.join(','),value) end end else eval("hash[:#{key}]=value") end else hash[key]=value end end def self.print_hash(indent,hash) max_length=0 hash.each { |name,value| max_length=name.to_s.length if name.to_s.length > max_length } max_length=max_length+1 index=0 hash.each do |name,value| prefix = "#{indent}#{name.to_s}".rjust(max_length) if value.kind_of?(Hash) print_hash(prefix+",",value) elsif value.kind_of?(Array) value.each do |v| if v.kind_of?(Hash) puts prefix.foreground(:yellow).bright print_hash( prefix + " ".rjust(max_length),v) end puts prefix.foreground(:yellow).bright + " " + v.to_s.foreground(:green) if v.kind_of?(String) prefix = indent + " ".rjust(max_length-1) end else puts prefix.foreground(:yellow).bright + " " + value.to_s.foreground(:green) end index+=1 indent=" ".rjust(indent.length) end end end