Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/p6/menu.rb
Overview
Clase menu que almacena un vector de platos y un vector de precios
Instance Attribute Summary collapse
-
#nombre_ ⇒ Object
Returns the value of attribute nombre_.
-
#platos_ ⇒ Object
Returns the value of attribute platos_.
-
#precios_ ⇒ Object
Returns the value of attribute precios_.
Instance Method Summary collapse
-
#initialize(nombre, &block) ⇒ Menu
constructor
Constructor de la clase menu.
- #plato(options = {}) ⇒ Object
- #precioTotal ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(nombre, &block) ⇒ Menu
Constructor de la clase menu
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/p6/menu.rb', line 5 def initialize(nombre, &block) @nombre_ = nombre @platos_ = [] @precios_ = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#nombre_ ⇒ Object
Returns the value of attribute nombre_.
3 4 5 |
# File 'lib/p6/menu.rb', line 3 def nombre_ @nombre_ end |
#platos_ ⇒ Object
Returns the value of attribute platos_.
3 4 5 |
# File 'lib/p6/menu.rb', line 3 def platos_ @platos_ end |
#precios_ ⇒ Object
Returns the value of attribute precios_.
3 4 5 |
# File 'lib/p6/menu.rb', line 3 def precios_ @precios_ end |
Instance Method Details
#plato(options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/p6/menu.rb', line 19 def plato(={}) @platos_ << [:plato] @precios_ << [:precio] end |
#precioTotal ⇒ Object
24 25 26 |
# File 'lib/p6/menu.rb', line 24 def precioTotal precios_.collect{|x| x}.reduce(:+) end |
#to_s ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/p6/menu.rb', line 28 def to_s output = "#{@nombre_}" output << " = #{precioTotal}€\n" output << "Contiene: \n" @platos_.zip(@precios_).collect{|x,y| output << "#{x} = #{y}€\n" } return output end |