class Nametrainer::Person

A class for persons with name, image, and score.

Create an instance with

person = Person.new(name, image)

Increase the score with

person.increase_score

You can sort Person instances by score:

person1 = Person.new('Albert', nil)
person2 = Person.new('Isaac', nil)
person1.increase_score
puts [person1, person2].sort.map{|p| p.name }  => Isaac, Albert

Attributes

image[R]
name[R]
score[RW]

Public Class Methods

new(name, image) click to toggle source
# File lib/nametrainer/person.rb, line 21
def initialize(name, image)
  @name = name
  @image = image
  @score = 0
end

Public Instance Methods

<=>(other) click to toggle source

Uses score for sorting.

# File lib/nametrainer/person.rb, line 33
def <=>(other)
  self.score <=> other.score
end
increase_score() click to toggle source

Increases the score by 1.

# File lib/nametrainer/person.rb, line 28
def increase_score
  @score += 1
end