Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:886283
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
require 'erb'
 
class WriterBinding
 
attr_reader :_eoutvar
 
def initialize(writer, context)
@_eoutvar = OutputWriter.new(writer)
for k,v in context
self.instance_variable_set("@#{k}",v)
end
end
 
def _eoutvar=(initial_value)
puts "ignoring the assignment to #{initial_value.inspect}, because I don't want to be a string!!"
end
 
class OutputWriter
def initialize(writer)
@writer = writer
end
def concat(string)
@writer.write(string)
end
end
end
 
t = ERB.new("Hello <%= @name %>", nil, nil, 'self._eoutvar')
 
writer = Object.new
def writer.write(bytes)
print "<chunk>#{bytes}</chunk>"
end
 
cxt = WriterBinding.new(writer, :name => 'Charles')
 
t.result(cxt.instance_eval {binding})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.