Skip to content

Instantly share code, notes, and snippets.

View benkoshy's full-sized avatar

Ben Koshy benkoshy

View GitHub Profile
@benkoshy
benkoshy / fizzbuzz.md
Created April 19, 2017 08:27
FizzBuzz kata
# 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
end
@benkoshy
benkoshy / fizzbuzz-tests.md
Created April 19, 2017 08:32
FizzBuzz tests
gem '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", expected
@benkoshy
benkoshy / change_kata.md
Last active April 23, 2017 11:12
Kata on exchanging coins
class Currency	

	# initialize with the dollar value that you
	# would like converted into coins:
	
	def initialize(amount)
		@amount = amount		
	end
@benkoshy
benkoshy / change_kata_tests.md
Last active April 20, 2017 11:05
Change Kata tests
# 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"
@benkoshy
benkoshy / oop-lesson-duck-typing1.md
Created April 23, 2017 00:59
OOP lesson - duck typing 1
# 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 
@benkoshy
benkoshy / oop-lesson-duck-typing2.md
Created April 23, 2017 01:00
OOP lesson - duck typing 2
    case random_object
    when Class1
        do_this
    when Class2
        do_that
    when Class3
        do_this_and_that
    end
@benkoshy
benkoshy / oop-lesson-duck-typing3.md
Created April 23, 2017 01:01
OOP lesson - duck typing 3
  # 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
@benkoshy
benkoshy / code-review-encryption1.md
Created April 24, 2017 23:05
Dependencies example - code review1
# dependencies example
class Bat
  def home_run
    ball = Ball.new
    ball.over_the_bleachers()
  end
end
@benkoshy
benkoshy / Factorial-Kata-simple.md
Created April 25, 2017 13:35
Factorial Kata - A simple solution
# 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)
@benkoshy
benkoshy / Factorial-Kata-complex.md
Created April 25, 2017 13:43
Factorial Complex version - recursion explicitly handled with polymorphism
class Factorial
	attr_reader :number

	def initialize(number=1)
		@number = number
	end

	def result