# my attempt at the fizz buzz kata
class Printer
def self.output
1.upto(15) do |n|
puts SpecialNumber.new(n).factory.print
end
end
endgem 'minitest', '~> 5.4'
require 'minitest/autorun'
require_relative '../lib/fizz_buzz'
class FizzTest < Minitest::Test
def test_is_divisiby_by_15_factory
expected = ::SpecialNumber.new(15).factory.print
assert_equal "fizzbuzz", expectedclass Currency
# initialize with the dollar value that you
# would like converted into coins:
def initialize(amount)
@amount = amount
end# probably not the most DRY.
# you'd want to DRY it up just in case you screwed up
# some of the test itself.
# i spent a good 40 minutes trying to work out where I went wrong.
# it turns out that the problem was not in the code, but in the tests!
# I had to skip all the tests to finally work out what was going on.
require "minitest/autorun"
require_relative "../lib/change"# the reader must please forgive me for
# the army analogy. I could not think of
# any other given the 5 seconds I devoted
def ready_weapon(weapon)
case weapon
when MachineGun
weapon.remove_safety_lock
weapon.load_bullets case random_object
when Class1
do_this
when Class2
do_that
when Class3
do_this_and_that
end # ignore the fact that the name
# of the method and its end result
# are virtually identical (for the moment)
def ready_weapon(weapon)
weapon.ready_weapon
end# dependencies example
class Bat
def home_run
ball = Ball.new
ball.over_the_bleachers()
end
end# a simple implementation
# notice how the recursion is not explicit - it's implicit
# where as the other solution
# it is explicit and is thus a little harder to read and understand
# personally I think the below approach should trump the explicit
# way because it's much more readable.
class NormalFactorial
def get_factorial(number)class Factorial
attr_reader :number
def initialize(number=1)
@number = number
end
def result