Class: Individuo
- Inherits:
-
Object
- Object
- Individuo
- Includes:
- Comparable
- Defined in:
- lib/etiqueta_nutricional/individuo.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#edad ⇒ Object
readonly
Returns the value of attribute edad.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#sexo ⇒ Object
readonly
Returns the value of attribute sexo.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(nombre, edad, sexo) ⇒ Individuo
constructor
A new instance of Individuo.
- #obtener_edad ⇒ Object
- #obtener_nombre ⇒ Object
- #to_s ⇒ Object
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
#edad ⇒ Object (readonly)
Returns the value of attribute edad.
3 4 5 |
# File 'lib/etiqueta_nutricional/individuo.rb', line 3 def edad @edad end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
3 4 5 |
# File 'lib/etiqueta_nutricional/individuo.rb', line 3 def nombre @nombre end |
#sexo ⇒ Object (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_edad ⇒ Object
17 18 19 |
# File 'lib/etiqueta_nutricional/individuo.rb', line 17 def obtener_edad @edad end |
#obtener_nombre ⇒ Object
13 14 15 |
# File 'lib/etiqueta_nutricional/individuo.rb', line 13 def obtener_nombre @nombre end |
#to_s ⇒ Object
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 |