Skip to content

Instantly share code, notes, and snippets.

@kangkyu
Created November 11, 2015 00:02
Show Gist options
  • Save kangkyu/b1f32b8685263c41d1ff to your computer and use it in GitHub Desktop.
Save kangkyu/b1f32b8685263c41d1ff to your computer and use it in GitHub Desktop.
Today's Kata 11-10-2015
# add a logger to this class, such that there is only one logger, that writes to a file called ./logfile.txt
class Charlie
class Logger
def self.log(number)
File.open("./logfile.txt", "a") do |f|
f.puts "#{number}"
end
end
def log(number)
File.open("./logfile.txt", "a") do |f|
f.puts "#{number}"
end
end
end
def initialize
@logger = Logger.new
end
def random_number
Logger.log rand(10000000)
# @logger.log rand(10000000)
end
end
# so if I say
c = Charlie.new
c.random_number
c.random_number
# both times -- those statements log the random number to the same logger instance
# one logger instance per charlie instance
# ok well onto part two -- one logger instance for all charlie instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment