Class: Platodsl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ Platodsl

Returns a new instance of Platodsl.



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

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

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

Instance Attribute Details

#alimentosObject

Returns the value of attribute alimentos.



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

def alimentos
  @alimentos
end

#nombreObject

Returns the value of attribute nombre.



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

def nombre
  @nombre
end

Instance Method Details

#alimento(aliment) ⇒ Object



18
19
20
# File 'lib/platodsl.rb', line 18

def alimento(aliment)
    @alimentos << aliment
end

#to_sObject



22
23
24
25
26
27
# File 'lib/platodsl.rb', line 22

def to_s
    output = "\n\n#{@nombre}"
    output << "\n#{'=' * @nombre.size}\n\n"
    output << "Alimentos: \n#{@alimentos.join(', ')}\n\n"
    output
end