Forum: Ruby Question on a card game I'm making

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9b7b90158e6bb466928f602fa9d523d0?d=identicon&s=25 Eli White (snugitup)
on 2016-09-07 00:10
I have a series of cards as classes. My deck class will generate a .new
version of all the cards a certain number of times to populate the deck
with cards. My player class then accesses the deck with .sample and
pushes them into an array called player_hand of size 5. The problem I'm
stuck on is finding a good way to display all of the card
information(atk, def, type, name, hp) to the player by expanding each
cards "traits" that they are currently holding in @player_hand.


class Player
   include Battle
   attr_accessor :player_hp, player_hand

  def initialize(player_hp=P_MAX_HP)
   @player_hp = player_hp
   @player_name = player_name
   @player_hand = player_hand[]


  def get_player_name
    @player_name = gets.chomp

  def alive?(player_hp)
    @playerhp > 0

  def new_hand
    new_hand =
    5.times do new_hand.push(@@deck.sample); end
    @player_hand = new_hand

  def draw
    until @player_hand.size == 5
  def inspect_card

Here's some example cards(for now we will use 3) id like to display:

class FireBunny < Card
  traits :atk, :defense, :type, :num, :hp
  atk 4
  defense 2
  type "fire"
  num 1
  hp 10

class WaterBug < Card
   traits :atk, :defense, :type, :num, :hp
   atk 2
   defense 4
   type "water"
   num 2
   hp 14

class LandWorm < Card
  traits :atk, :defense, :type, :num, :hp
  atk 3
  defense 3
  type "land"
  num 3
  hp 12

(pardon my silly names)

After they are in the array, i will have to write a display method
corresponding to the cards by making the player type 1 , 2 , 3 , 4 , 5
for each card in their hand. my only question is is how to display their
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2016-09-07 21:16
I can't see from this code how you're holding each card's attributes,
but the simplest way would be to store them in a Hash and then display
the Hash.
This topic is locked and can not be replied to.