Skip to content

Instantly share code, notes, and snippets.

@ttanimichi
Created November 22, 2015 10:02
Show Gist options
  • Select an option

  • Save ttanimichi/6a8bd8f18364f2f39a8c to your computer and use it in GitHub Desktop.

Select an option

Save ttanimichi/6a8bd8f18364f2f39a8c to your computer and use it in GitHub Desktop.
require 'singleton'
class MyLogger
include Singleton
def initialize
@logger = $stdout
end
def write(msg)
@logger.puts msg
end
end
MyLogger.instance.write('hoge')
module MyLogger2
class << self
def write(msg)
logger.puts msg
end
def logger
@logger ||= $stdout
end
end
end
MyLogger2.write 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment