Class: Kitchen::Pantry
- Includes:
- Enumerable
- Defined in:
- lib/kitchen/pantry.rb
Overview
A place to store labeled items during recipe work. Essentially, a slightly improved hash.
Instance Method Summary collapse
-
#each {|label, item| ... } ⇒ Object
Iterate over the pantry items.
-
#get(label) ⇒ Object
Get an item from the pantry.
-
#get!(label) ⇒ Object
Get an item from the pantry, raising if not present.
-
#size ⇒ Integer
Returns the number of items in the pantry.
-
#store(item, label:) ⇒ Object
Adds an item to the pantry with the provided label.
Instance Method Details
#each {|label, item| ... } ⇒ Object
Iterate over the pantry items
43 44 45 |
# File 'lib/kitchen/pantry.rb', line 43 def each(&block) @hash.each { |k, v| block.call(k, v) } end |
#get(label) ⇒ Object
Get an item from the pantry
23 24 25 |
# File 'lib/kitchen/pantry.rb', line 23 def get(label) @hash[label.to_sym] end |
#get!(label) ⇒ Object
Get an item from the pantry, raising if not present
33 34 35 |
# File 'lib/kitchen/pantry.rb', line 33 def get!(label) get(label) || raise(RecipeError, "There is no pantry item labeled '#{label}'") end |
#size ⇒ Integer
Returns the number of items in the pantry
51 52 53 |
# File 'lib/kitchen/pantry.rb', line 51 def size @hash.keys.size end |
#store(item, label:) ⇒ Object
Adds an item to the pantry with the provided label
14 15 16 |
# File 'lib/kitchen/pantry.rb', line 14 def store(item, label:) @hash[label.to_sym] = item end |