Class: Pairity::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/pairity/person.rb

Constant Summary collapse

@@id =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, tier: 2) ⇒ Person

Returns a new instance of Person.



7
8
9
10
# File 'lib/pairity/person.rb', line 7

def initialize(name:, tier: 2)
  @name = name
  @tier = !((1..3) === tier) ? 2 : tier
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/pairity/person.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/pairity/person.rb', line 5

def name
  @name
end

#tierObject

Returns the value of attribute tier.



5
6
7
# File 'lib/pairity/person.rb', line 5

def tier
  @tier
end

Instance Method Details

#<=>(other_person) ⇒ Object



12
13
14
15
16
# File 'lib/pairity/person.rb', line 12

def <=>(other_person)
  return 1 if name == "Han Solo"
  return -1 if other_person.name == "Han Solo"
  name <=> other_person.name
end

#to_sObject



18
19
20
# File 'lib/pairity/person.rb', line 18

def to_s
  "#{name}"
end