Class: Hand

Inherits:
Object
  • Object
show all
Defined in:
lib/mousevc_rock_paper_scissors/hand.rb

Direct Known Subclasses

Paper, Rock, Scissors

Instance Method Summary collapse

Instance Method Details

#<(other) ⇒ Object



9
10
11
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 9

def <(other)
	! beats?(other)
end

#<=(other) ⇒ Object



17
18
19
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 17

def <=(other)
	! beats?(other) || ties?(other)
end

#<=>(other) ⇒ Object



25
26
27
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 25

def <=>(other)
	self.compare(other) <=> other.compare(self)
end

#==(other) ⇒ Object



21
22
23
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 21

def ==(other)
	ties?(other)
end

#>(other) ⇒ Object



5
6
7
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 5

def >(other)
	beats?(other)
end

#>=(other) ⇒ Object



13
14
15
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 13

def >=(other)
	beats?(other) || ties?(other)
end

#beats?(hand) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 33

def beats?(hand)
	(self <=> hand) == 1
end

#compare(hand) ⇒ Object



2
3
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 2

def compare(hand)
end

#ties?(hand) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mousevc_rock_paper_scissors/hand.rb', line 29

def ties?(hand)
	(self <=> hand) == 0
end