-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.rb
39 lines (29 loc) · 784 Bytes
/
card.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#A Card has two useful bits of information:
#its face value, and whether it is face-up or face-down.
#You'll want instance variables to keep track of this information.
#You'll also want a method to display information about the card:
#nothing when face-down, or its value when face-up.
#I also wrote #hide, #reveal, #to_s, and #== methods.
#Common problem: Having issues with #hide and #reveal? Try testing small.
class Card
attr_reader :value
def initialize(faceup = true,value)
@faceup = faceup
@value = value
end
def hide
@faceup = false
end
def reveal
@faceup = true
end
def faceup?
@faceup
end
def to_s
faceup? ? value.to_s : " "
end
def ==(object)
object.is_a?(self.class) && object.value == value
end
end