Class: Individuo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/InforNutricional/icc.rb

Overview

Clase que representa los datos básicos de un Individuo

Direct Known Subclasses

Paciente

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, edad, sexo) ⇒ Individuo

Método para inicializar y hacer new



8
9
10
11
12
13
14
# File 'lib/InforNutricional/icc.rb', line 8

def initialize(nombre, edad, sexo) 
    #Variables de instancia
    @nombre = nombre
    @edad = edad
    @sexo = sexo

end

Instance Attribute Details

#edadObject (readonly)

Returns the value of attribute edad.



4
5
6
# File 'lib/InforNutricional/icc.rb', line 4

def edad
  @edad
end

#nombreObject (readonly)

Returns the value of attribute nombre.



4
5
6
# File 'lib/InforNutricional/icc.rb', line 4

def nombre
  @nombre
end

#sexoObject (readonly)

Returns the value of attribute sexo.



4
5
6
# File 'lib/InforNutricional/icc.rb', line 4

def sexo
  @sexo
end

Instance Method Details

#<=>(other) ⇒ Object

Método comparable



21
22
23
24
25
26
# File 'lib/InforNutricional/icc.rb', line 21

def  <=>(other) # Método comparable
    return nil unless other.instance_of?Individuo
        @nombre <=> other.nombre
        @edad <=> other.edad
        @sexo <=> other.sexo
end

#to_sObject

Método para mostrar los resultados.



16
17
18
# File 'lib/InforNutricional/icc.rb', line 16

def to_s() #Método para mostrar los resultados.
    "Datos del individuo: #{@nombre}. Edad: #{@edad}. Sexo: #{@sexo}. "
end