In Ruby you must print with puts
or print
. Just returning the string doesn't print it. The reason your Dealer class prints is because you did a print
, but in your Player
class, as you noted, you had no print. You only returned the string without printing.
As you noted, you were able to fix it by including the print:
def show_card
print "[#{@card_type} of #{@suit}]"
end
You could do this instead:
def show_card
"[#{@card_type} of #{@suit}]"
end
...
module Hand
def show_hand
if self.class == Dealer
#Need to cover up 1 of the 2 cards here. Dealer doesn't show both!
print "The dealer is showing: "
puts self.hand[0].show_card # PRINT THE CARD
elsif self.class == Player
print "You have: "
self.hand.each do |item|
print item.show_card # PRINT THE CARD
end
puts ''
else
puts "A Random person is showing their hand."
end
end
end
Which would be a little more "symmetrical" and prints what you want.
A slightly more compact would be:
def show_card
"[#{@card_type} of #{@suit}]"
end
...
module Hand
def show_hand
if self.class == Dealer
#Need to cover up 1 of the 2 cards here. Dealer doesn't show both!
puts "The dealer is showing: #{self.hand[0].show_card}"
elsif self.class == Player
print "You have: "
self.hand.each { |item| print item.show_card }
puts ''
else
puts "A Random person is showing their hand."
end
end
end