Created
March 10, 2011 17:08
-
-
Save wycats/864468 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
class ReadAdapter #:nodoc: internal use only | |
def initialize(block) | |
@block = block | |
end | |
def inspect | |
"#<#{self.class}>" | |
end | |
def <<(str) | |
call_block(str, &@block) if @block | |
end | |
private | |
# This method is needed because @block must be called by yield, | |
# not Proc#call. You can see difference when using `break' in | |
# the block. | |
def call_block(str) | |
yield str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment