Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#access(path) ⇒ Object Also known as: vine


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vine.rb', line 14

def access(path)
  value = self
  
  path.to_s.split('.').each do |p|
    if p.to_i.to_s == p
      value = value[p.to_i]
    else
      value = value[p].nil? ? value[p.to_sym] : value[p]
    end
    break if value.nil?
  end
  
  value
end