class Bowling::Ball

Attributes

ball_position[RW]
frame[RW]
knocked_pins[RW]
score[RW]

Public Class Methods

new( ball_position, frame, knocked_pins = nil ) click to toggle source

Construction ===

# File lib/bowling/ball.rb, line 9
def initialize( ball_position, frame, knocked_pins = nil )
  @ball_position = ball_position
  @frame         = frame
  @knocked_pins  = knocked_pins || 0
end

Public Instance Methods

first_ball?() click to toggle source
# File lib/bowling/ball.rb, line 45
def first_ball?
  ball_position == 0 
end
knock_over( amount ) click to toggle source

Public methods ===

# File lib/bowling/ball.rb, line 18
def knock_over( amount )
  knocked_pins += amount
  raise Error.new 'Knocked pins can not exceed 10' if knocked_pins > 10
end
next_ball() click to toggle source
# File lib/bowling/ball.rb, line 24
def next_ball
  if strike?
    frame.next_frame.first_ball
  else
    frame.balls[ball_position + 1]
  end
end
perfect?() click to toggle source
# File lib/bowling/ball.rb, line 40
def perfect?
  knocked_pins == 10
end
strike?() click to toggle source

Calculations ===

# File lib/bowling/ball.rb, line 35
def strike?
  first_ball? and perfect?
end