Class: Nutri::Persona

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nutri/persona.rb

Direct Known Subclasses

Antropometrico

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, apellido, edad, sexo) ⇒ nil

Initialize

Parameters:

  • nombre (char)
    name
  • apellido (char)
    surname
  • edad (int)
    age
  • sexo (inr)
    sex: 0= hombre, 1=mujer


23
24
25
# File 'lib/nutri/persona.rb', line 23

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

Instance Attribute Details

#apellidoObject

getters y setters



11
12
13
# File 'lib/nutri/persona.rb', line 11

def apellido
  @apellido
end

#edadObject

getters y setters



11
12
13
# File 'lib/nutri/persona.rb', line 11

def edad
  @edad
end

#nombreObject

getters y setters



11
12
13
# File 'lib/nutri/persona.rb', line 11

def nombre
  @nombre
end

#sexoObject

getters y setters



11
12
13
# File 'lib/nutri/persona.rb', line 11

def sexo
  @sexo
end

Instance Method Details

#<=>(other) ⇒ bool

Compara los objetos sobre su edad

Parameters:

  • other (object)
    Person object

Returns:

  • (bool)
    true or false


64
65
66
67
68
69
70
# File 'lib/nutri/persona.rb', line 64

def <=>(other)
    if other.is_a? Persona
        @edad <=> other.edad
    else
        false
    end
end

#apellido_to_schar

surname to string

Returns:

  • (char)
    surname as string


39
40
41
# File 'lib/nutri/persona.rb', line 39

def apellido_to_s
    "Apellido: #{@apellido}\n"
end

#edad_to_schar

age to string

Returns:

  • (char)
    age as string


47
48
49
# File 'lib/nutri/persona.rb', line 47

def edad_to_s
    "Edad: #{@edad}\n"
end

#formato_to_schar

Devuelve el string representado por el objeto como un char

Returns:

  • (char)
    name and surname as string


76
77
78
# File 'lib/nutri/persona.rb', line 76

def formato_to_s
    puts "Nombre: #{@nombre}, Apellido: #{@apellido}, Edad: #{@edad}, Sexo: #{@sexo}"
end

#nombre_to_schar

name to string

Returns:

  • (char)
    name as string


31
32
33
# File 'lib/nutri/persona.rb', line 31

def nombre_to_s
    "Nombre: #{@nombre}\n"
end

#sexo_to_schar

sex to string

Returns:

  • (char)
    sex as string


55
56
57
# File 'lib/nutri/persona.rb', line 55

def sexo_to_s
    "Sexo: #{@sexo}\n"
end