A
Andrés Suárez
Hi,
I'm trying to obtain the cards of a Deck in a string like
"2s...KsAs2h...Ah2d...Ad2c...Ac". The problem with the folowing code is
that in the end of the string appears "#<Deck:0x2bb5880>". Why? Can I
avoid it?
class Deck
SUITS = %w{s d h c}
RANKS = %w{2 3 4 5 6 7 8 9 T J Q K A}
def initialize
@cards = []
SUITS.each{ |s| RANKS.each{ |r| @cards << r+s } }
end
def popCard
@cards.pop
end
def to_s
@cards.map{ |card| print card}
end
end
d0 = Deck.new
puts d0
Regards,
Andrés
I'm trying to obtain the cards of a Deck in a string like
"2s...KsAs2h...Ah2d...Ad2c...Ac". The problem with the folowing code is
that in the end of the string appears "#<Deck:0x2bb5880>". Why? Can I
avoid it?
class Deck
SUITS = %w{s d h c}
RANKS = %w{2 3 4 5 6 7 8 9 T J Q K A}
def initialize
@cards = []
SUITS.each{ |s| RANKS.each{ |r| @cards << r+s } }
end
def popCard
@cards.pop
end
def to_s
@cards.map{ |card| print card}
end
end
d0 = Deck.new
puts d0
Regards,
Andrés