Class: MenuDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/nutriente/menuDSL.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, precio, &block) ⇒ MenuDSL

Returns a new instance of MenuDSL.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nutriente/menuDSL.rb', line 5

def initialize(nombre, precio, &block)
    @nombre = nombre
    @precio = precio
    @platos = []

    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval(&block)
        end
    end
end

Instance Attribute Details

#nombreObject

Returns the value of attribute nombre.



3
4
5
# File 'lib/nutriente/menuDSL.rb', line 3

def nombre
  @nombre
end

#platosObject

Returns the value of attribute platos.



3
4
5
# File 'lib/nutriente/menuDSL.rb', line 3

def platos
  @platos
end

#precioObject

Returns the value of attribute precio.



3
4
5
# File 'lib/nutriente/menuDSL.rb', line 3

def precio
  @precio
end

Instance Method Details

#plato(p, opcion = {}) ⇒ Object



28
29
30
# File 'lib/nutriente/menuDSL.rb', line 28

def plato(p, opcion = {})
  @platos << p
end

#to_sObject



19
20
21
22
23
24
25
# File 'lib/nutriente/menuDSL.rb', line 19

def to_s
  output = @nombre
  output << " #{@precio}€"
  output << "\n#{'-' * @nombre.size}\n"
  #output << "#{puts @platos}\n"

  output
end