Skip to content

Instantly share code, notes, and snippets.

@monzou
Created May 7, 2011 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monzou/960543 to your computer and use it in GitHub Desktop.
Save monzou/960543 to your computer and use it in GitHub Desktop.
require "delegate"
class Support
def initialize(prefix)
@prefix = prefix
@lines = []
end
def write(s)
@lines << "#{@prefix} #{s}"
end
def flush
@lines.each { |line| puts line }
@lines = []
end
end
class Client < DelegateClass(Support)
def initialize(support)
super(support)
end
def write_header
write(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
end
def write_footer
write(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
end
end
client = Client.new(Support.new("delegate"))
client.write_header
client.write("Hello, World !")
client.write_footer
client.flush
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment