[ create a new paste ] login | about

Link: http://codepad.org/ArpNqs1k    [ raw code | output | fork ]

Ruby, pasted on Dec 28:
class Registry
  def initialize(filename)
    
    @registry = {
        "HKEY_ROOT" => [ ],
        "HKEY_ROOT\\Configuration" => [ ],
        "HKEY_ROOT\\Configuration\\RACK" => [ ],
        "HKEY_ROOT\\Configuration\\Thin" => [ ],
        "HKEY_ROOT\\Configuration\\Mongrel" => [ ],
        "HKEY_ROOT\\Configuration\\WEBRick" => [ ],
        "HKEY_ROOT\\Web Servers" => [ ],
        "HKEY_ROOT\\Web Servers\\RACK" => [ ],
        "HKEY_ROOT\\Web Servers\\Thin" => [ ],
        "HKEY_ROOT\\Web Servers\\Mongrel" => [ ],
        "HKEY_ROOT\\Web Servers\\WEBRick" => [ ],
    }
    
  end
  
  def [] path
    parts = path.split( "\\" )
 
    if @registry.key?(path) == true
      @registry[path]
    else
        my_path, tmp_path = [], []
        
        parts.each_with_object(my_path) {
          | part, thePath |
          
          if @registry.key?(thePath.join("\\")) == false
              if thePath == parts
                node = @registry[tmp_path.join("\\")]
                node[parts.last]
              end
          else
            my_path << part
            
            if @registry.key?(thePath.join("\\")) == true
              tmp_path << part
            end
          end
          
          puts "parts:%s tmp_path:%s my_path:%s" % [ (parts.inspect).to_s, (tmp_path).inspect, (my_path).inspect ]
          part
        }
        
        raise "%s:  Path does not exist." % my_path.join("\\")
    end
  end
end

config = Registry.new( "config" )
puts config["HKEY_ROOT\\Configuration\\RACK\\Server Port"].inspect 


Output:
1
2
Line 28:in `[]': undefined method `each_with_object' for ["HKEY_ROOT", "Configuration", "RACK", "Server Port"]:Array (NoMethodError)
	from t.rb:54


Create a new paste based on this one


Comments: