Class: RubyPlayingCards::Hand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards, player) ⇒ Hand

Returns a new instance of Hand.



6
7
8
9
# File 'lib/ruby_playing_cards/hand.rb', line 6

def initialize(cards, player)
  @cards = cards
  @player = player
end

Instance Attribute Details

#cardsObject

Returns the value of attribute cards.



4
5
6
# File 'lib/ruby_playing_cards/hand.rb', line 4

def cards
  @cards
end

#playerObject

Returns the value of attribute player.



4
5
6
# File 'lib/ruby_playing_cards/hand.rb', line 4

def player
  @player
end

Instance Method Details

#add_cards(cards) ⇒ Object



11
12
13
# File 'lib/ruby_playing_cards/hand.rb', line 11

def add_cards(cards)
  @cards << cards
end

#sizeObject



15
16
17
# File 'lib/ruby_playing_cards/hand.rb', line 15

def size
  @cards.size
end

#to_sObject



19
20
21
22
23
24
# File 'lib/ruby_playing_cards/hand.rb', line 19

def to_s
  puts "Player #{@player}: "
  @cards.map do |card|
    card.to_s    
  end
end