Class: PlatoDSL
- Inherits:
-
Object
- Object
- PlatoDSL
- Defined in:
- lib/p6/menu.rb
Instance Attribute Summary collapse
-
#ingredientes ⇒ Object
Returns the value of attribute ingredientes.
-
#nombre(name) ⇒ Object
Returns the value of attribute nombre.
-
#peso ⇒ Object
Returns the value of attribute peso.
Instance Method Summary collapse
- #alimento(options = {}) ⇒ Object
-
#initialize(&block) ⇒ PlatoDSL
constructor
A new instance of PlatoDSL.
- #to_s ⇒ Object
Constructor Details
#initialize(&block) ⇒ PlatoDSL
Returns a new instance of PlatoDSL.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/p6/menu.rb', line 8 def initialize(&block) @nombre @ingredientes = [] @peso = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#ingredientes ⇒ Object
Returns the value of attribute ingredientes.
6 7 8 |
# File 'lib/p6/menu.rb', line 6 def ingredientes @ingredientes end |
#nombre(name) ⇒ Object
Returns the value of attribute nombre.
6 7 8 |
# File 'lib/p6/menu.rb', line 6 def nombre @nombre end |
#peso ⇒ Object
Returns the value of attribute peso.
6 7 8 |
# File 'lib/p6/menu.rb', line 6 def peso @peso end |
Instance Method Details
#alimento(options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/p6/menu.rb', line 31 def alimento( = {}) @ingredientes << [:nombre] if [:nombre] @pesos << [:peso] if [:peso] end |
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/p6/menu.rb', line 21 def to_s output = @nombre output << "\nIngredients:\n\n" @ingredientes.zip(@peso).each do |alimento, peso1| output << "\n " << alimento output << "\n Peso: " << peso1.to_s end output end |