Created
May 7, 2011 14:34
-
-
Save monzou/960543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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