Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created July 31, 2011 01:40
Show Gist options
  • Select an option

  • Save ajsharp/1116248 to your computer and use it in GitHub Desktop.

Select an option

Save ajsharp/1116248 to your computer and use it in GitHub Desktop.
def compile_template_method(locals)
source, offset = precompiled(locals)
offset += 5
method_name = "__tilt_#{Thread.current.object_id.abs}"
Object.class_eval <<-RUBY, eval_file, line - offset
#{extract_magic_comment source}
TOPOBJECT.class_eval do
def #{method_name}(locals)
Thread.current[:tilt_vars] = [self, locals]
class << self
this, locals = Thread.current[:tilt_vars]
this.instance_eval do
#{source}
end
end
end
end
RUBY
unbind_compiled_method(method_name)
end
def unbind_compiled_method(method_name)
method = TOPOBJECT.instance_method(method_name)
TOPOBJECT.class_eval { remove_method(method_name) }
method
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment