Class: Individuo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/etiqueta_nutricional/individuo.rb

Direct Known Subclasses

Paciente

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, edad, sexo) ⇒ Individuo

Returns a new instance of Individuo.



7
8
9
10
11
# File 'lib/etiqueta_nutricional/individuo.rb', line 7

def initialize(nombre, edad, sexo)
    @nombre = nombre
    @edad = edad
    @sexo = sexo
end

Instance Attribute Details

#edadObject (readonly)

Returns the value of attribute edad.



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

def edad
  @edad
end

#nombreObject (readonly)

Returns the value of attribute nombre.



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

def nombre
  @nombre
end

#sexoObject (readonly)

Returns the value of attribute sexo.



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

def sexo
  @sexo
end

Instance Method Details

#<=>(other) ⇒ Object



35
36
37
38
# File 'lib/etiqueta_nutricional/individuo.rb', line 35

def <=>(other)
    return nil unless other.instance_of? Individuo
    @edad <=> other.edad
end

#obtener_edadObject



17
18
19
# File 'lib/etiqueta_nutricional/individuo.rb', line 17

def obtener_edad
    @edad
end

#obtener_nombreObject



13
14
15
# File 'lib/etiqueta_nutricional/individuo.rb', line 13

def obtener_nombre
    @nombre
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/etiqueta_nutricional/individuo.rb', line 21

def to_s
    cadena = ""
    sexo = ""
    cadena = cadena + "Nombre: #{@nombre}\n"
    cadena = cadena + "Edad: #{@edad}\n"
    if @sexo == 0
        sexo = "Hombre"
    else
        sexo = "Mujer"
    end
    cadena = cadena + "Sexo: #{sexo}\n"
    return cadena
end