Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/practica/menu.rb
Instance Attribute Summary collapse
-
#desc_menus ⇒ Object
readonly
Returns the value of attribute desc_menus.
-
#menu ⇒ Object
readonly
Returns the value of attribute menu.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#precios ⇒ Object
readonly
Returns the value of attribute precios.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #componente(bloque = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Menu
constructor
A new instance of Menu.
- #precio(coste) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Menu
Returns a new instance of Menu.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/practica/menu.rb', line 3 def initialize(name, &block) @name = name @desc_menus = [] @menu = [] @precios = [] @total=0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#desc_menus ⇒ Object (readonly)
Returns the value of attribute desc_menus.
2 3 4 |
# File 'lib/practica/menu.rb', line 2 def @desc_menus end |
#menu ⇒ Object (readonly)
Returns the value of attribute menu.
2 3 4 |
# File 'lib/practica/menu.rb', line 2 def @menu end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/practica/menu.rb', line 2 def name @name end |
#precios ⇒ Object (readonly)
Returns the value of attribute precios.
2 3 4 |
# File 'lib/practica/menu.rb', line 2 def precios @precios end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
2 3 4 |
# File 'lib/practica/menu.rb', line 2 def total @total end |
Instance Method Details
#componente(bloque = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/practica/menu.rb', line 19 def componente(bloque = {}) @desc_menus << bloque[:descripcion] @menu << bloque[:platos] @precios << bloque[:precio] end |
#precio(coste) ⇒ Object
24 25 26 27 |
# File 'lib/practica/menu.rb', line 24 def precio(coste) @total=coste[:precio] end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/practica/menu.rb', line 29 def to_s text = @name + "\n" for i in 0..@desc_menus.length-1 do text << "\t- #{@desc_menus[i]}\n" text << "\t\t#{@menu[i]}" text <<"\n" text << "\t\t#{@precios[i]} €\n" end text<<"\n#{@total}" text end |