Beginner Needs Help

def build_deck
  0.upto(51) {|i| @deck.push(i.divmod(13))}
  # deck consists of 52 2-member arrays, [suit, rank],
  # each representing a playing card. In use, the first
  # 13 members is hand[0] and the next 13 are hand[1], etc.
  # hand will be defined in a subclass.
  return @deck
end

[...]

def initialize
   super
  @hands = Array.new(4) {|idx| Array.new(4)}
  # hands is a 4 by 4 array for player,suit
end

[...]

def build_hands
  self.shuffle_deck
   0.upto(51) {|i| @hands[i/13][@deck[i][0]] += 0b1 << @deck[i][1]}

IRB shows @hands looks like:

irb(main):024:0> hands = Array.new(4) {|idx| Array.new(4)}
=> [[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil],

[nil, nil, nil, nil]]

So,

@hands[0][@deck[0][0]]

is:

@hands[0][0]

which is fetching the first 'nil' shown above in IRB.

Regards,

Bill

Ah, thanks Bill and others who might respond. All I have to do is set the
initial values of hands to 0, not nil.

beep beep

Charlie