Module: Fossicker

Defined in:
lib/fossicker.rb,
lib/fossicker/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fossick(object, *keys, **options, &block) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/fossicker.rb', line 4

def self.fossick(object, *keys, **options, &block)
  default = options.key?(:default) ? [ options[:default] ] : []
  keys.reduce(object) do |result, key|
    # We're taking advantage fof the fact that returning from a bloc exits the enclosing method. We invoke fetch
    # again to ensure we behave the same way with respect to defaults that Array#fetch and Hash#fetch do.
    result.fetch(key) { return result.fetch(key, *default, &block) }
  end
end

Instance Method Details

#fossick(*keys, **options, &block) ⇒ Object



13
14
15
# File 'lib/fossicker.rb', line 13

def fossick(*keys, **options, &block)
  Fossicker.fossick(self, *keys, **options, &block)
end