Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/lokale/agent.rb

Instance Method Summary collapse

Instance Method Details

#set_by_key_path(key_path, val) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lokale/agent.rb', line 10

def set_by_key_path(key_path, val)
  last_hash = self
  last_key = key_path.pop
  key_path.each do |k|
    if last_hash.has_key? k 
      last_hash = last_hash[k]
    else
      new_hash = Hash.new
      last_hash[k] = new_hash
      last_hash = new_hash
    end
  end
  
  last_hash[last_key] = val
end