Module: Fat

Defined in:
lib/fat.rb

Constant Summary collapse

FatError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.at(hash, *args, **keywords) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fat.rb', line 4

def self.at(hash, *args, **keywords)
  value = hash

  args.each_with_index do |field, index|
    value = value[field]
    if value.nil?
      if !keywords.empty?
        return keywords[:default]
      else
        raise Fat::FatError, "#{args[0..index].join(".")} is nil"
      end
    end
  end

  value
end

Instance Method Details

#at(*args, **keywords) ⇒ Object



21
22
23
# File 'lib/fat.rb', line 21

def at(*args, **keywords)
  Fat.at(self, *args, keywords)
end