class GunTest::Gun

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/gun_test/gun.rb, line 9
def initialize(name)
  @name = name
end

Public Instance Methods

reload(ammo) click to toggle source
# File lib/gun_test/gun.rb, line 13
def reload(ammo)
  # Only C++ supported by now!
  task "Reloading gun..." do
    say_status "Reloading".blue
    reloaded = system("g++ #{ammo} -O2 -o #{name} 2> /dev/null")

    say_status reloaded ? "Done".green : "Failed".red

    reloaded
  end
end
shoot(target_number = 50, &block) click to toggle source
# File lib/gun_test/gun.rb, line 25
def shoot(target_number = 50, &block)
  target_number.times do |i|
    break false unless task "Shot #{i+1}" do
      say_status "Reloading bullet...".blue

      shot = Shot.new
      shot.instance_exec(i, &block)

      say_status "Shooting!".blue
      headshot = shot.bang!(name)

      say_status headshot ? "Headshot!".green : "Failed".red

      headshot
    end
  end
end