Class: Kori

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(file_or_hash) ⇒ Object



9
10
11
# File 'lib/kori.rb', line 9

def create(file_or_hash)
  IceNine.deep_freeze(new(file_or_hash))
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
# File 'lib/kori.rb', line 25

def [](key)
  fetch(key, nil)
end

#fetch(*args) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kori.rb', line 29

def fetch(*args)
  arity = args.size
  raise ArgumentError, "invalid number of elements (#{arity} for 1..2)" unless arity.between?(1, 2)

  key, val = args
  if respond_to?(key.to_s)
    __send__(key.to_s)
  elsif arity == 2
    val
  else
    raise KeyError, "key '#{key}' not found"
  end
end

#get(key) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/kori.rb', line 16

def get(key)
  parts = key.split('.')
  curs = self
  while p = parts.shift
    curs = curs.__send__(p)
  end
  curs
end