class Kitchen::Pantry
A place to store labeled items during recipe work. Essentially, a slightly improved hash.
Public Class Methods
new()
click to toggle source
# File lib/kitchen/pantry.rb, line 57 def initialize @hash = {} end
Public Instance Methods
each(&block)
click to toggle source
Iterate over the pantry items
@yield Gives each label and item pair to the block @yieldparam label [Symbol] the item's label @yieldparam item [Object] the item
# File lib/kitchen/pantry.rb, line 43 def each(&block) @hash.each { |k, v| block.call(k, v) } end
get(label)
click to toggle source
Get an item from the pantry
@param label [String, Symbol] the item's label @return [Object]
# File lib/kitchen/pantry.rb, line 23 def get(label) @hash[label.to_sym] end
get!(label)
click to toggle source
Get an item from the pantry, raising if not present
@param label [String, Symbol] the item's label @raise [RecipeError] if there's no item for the label @return [Object]
# File lib/kitchen/pantry.rb, line 33 def get!(label) get(label) || raise(RecipeError, "There is no pantry item labeled '#{label}'") end
size()
click to toggle source
Returns the number of items in the pantry
@return [Integer]
# File lib/kitchen/pantry.rb, line 51 def size @hash.keys.size end
store(item, label:)
click to toggle source
Adds an item to the pantry with the provided label
@param item [Object] something to store @param label [String, Symbol] a label with which to retrieve this item later.
# File lib/kitchen/pantry.rb, line 14 def store(item, label:) @hash[label.to_sym] = item end