fail.rb

Reduced script - Magnus Holm, 03/22/2013 06:38 PM

Download (604 Bytes)

 
1
class Fail
2
  def render(scope = Object.new)
3
    compiled_method.bind(scope).call
4
  end
5

    
6
  def compiled_method
7
    @compiled_method ||= compile_template_method
8
  end
9

    
10
  def source
11
    "Hello world".inspect
12
  end
13

    
14
  def compile_template_method
15
    method_name = "__tilt_#{Thread.current.object_id.abs}"
16
    Object.class_eval("def #{method_name}; #{source} end")
17
    unbind_compiled_method(method_name)
18
  end
19

    
20
  def unbind_compiled_method(method_name)
21
    method = Object.instance_method(method_name)
22
    Object.class_eval { remove_method(method_name) }
23
    method
24
  end
25
end
26

    
27
loop do
28
  Fail.new.render
29
end
30