Class: Menu

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

Overview

Clase menu que almacena un vector de platos y un vector de precios

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
	@platos_ << options[:plato]
	@precios_ << options[:precio]
end

#precioTotalObject



24
25
26
# File 'lib/p6/menu.rb', line 24

def precioTotal
	precios_.collect{|x| x}.reduce(:+)
end

#to_sObject



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