Class: Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/pract06/menu.rb

Overview

Clase para representar un Menu con DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ Menu

Returns a new instance of Menu.



4
5
6
7
8
9
10
11
12
13
# File 'lib/pract06/menu.rb', line 4

def initialize(nombre,&block)
  @nombre = nombre
  @platos = []
  @precios=[]
  @preciototal =0.0
  
  if block_given?
    instance_eval(&block)
  end
end

Instance Attribute Details

#nombreObject

Returns the value of attribute nombre.



3
4
5
# File 'lib/pract06/menu.rb', line 3

def nombre
  @nombre
end

#platosObject

Returns the value of attribute platos.



3
4
5
# File 'lib/pract06/menu.rb', line 3

def platos
  @platos
end

#precio(total) ⇒ Object

Returns the value of attribute precio.



3
4
5
# File 'lib/pract06/menu.rb', line 3

def precio
  @precio
end

Instance Method Details

#componente(options = {}) ⇒ Object



15
16
17
18
# File 'lib/pract06/menu.rb', line 15

def componente(options={})
  @platos << options[:plato]
  @precios << options[:precio]
end

#to_sObject



24
25
26
27
28
29
30
31
32
# File 'lib/pract06/menu.rb', line 24

def to_s
  output = "#{@nombre}"
  output << " = #{@preciototal}€\n"
  output << "Contiene: \n"
  @platos.zip(@precios).each do |x,y|
    output << "#{x} = #{y}€\n"
  end
  output
end