Just like in Rails:

require 'erb'

template = ERB.new <<-TEMPLATE
This is a template from <%= @context %> with yield:

<%= yield %>

<%= yield :one, :two, :three %>

Text after yield
TEMPLATE

class Context
  def initialize
    @context = "context"
  end
  
  def get_binding
    binding
  end
  
  def handle_yield(args)
    "Yielding with args: #{args.inspect}"
  end
end

ctx = Context.new

template.run(ctx.get_binding{|*args| ctx.handle_yield(args)})