Class: Persona

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

Direct Known Subclasses

Paciente

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, sexo) ⇒ Persona



7
8
9
# File 'lib/alu0101042305/persona.rb', line 7

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

Instance Attribute Details

#nombreObject (readonly)

Returns the value of attribute nombre.



5
6
7
# File 'lib/alu0101042305/persona.rb', line 5

def nombre
  @nombre
end

#sexoObject (readonly)

Returns the value of attribute sexo.



5
6
7
# File 'lib/alu0101042305/persona.rb', line 5

def sexo
  @sexo
end

Instance Method Details

#<=>(other) ⇒ Object

Raises:

  • (TypeError)


11
12
13
14
15
# File 'lib/alu0101042305/persona.rb', line 11

def <=> other
  raise TypeError, "Se esperaba un objeto Persona" unless other.is_a?Persona
  return 1 if other.is_a?PacienteM
  return @nombre <=> other.nombre
end

#to_sObject



17
18
19
# File 'lib/alu0101042305/persona.rb', line 17

def to_s
  "#{@nombre} es un#{@sexo == 'mujer' ? 'a' : nil} #{@sexo}"
end