module Sinatra::Delegator

def self.delegate(*methods)

def self.delegate(*methods)
  methods.each do |method_name|
    # Replaced with way shorter and better implementation in 1.3.0
    # using define_method instead, however, blocks cannot take block
    # arguments on 1.8.6.
    begin
      code = TEMPLATE % [method_name, method_name]
      eval code, binding, '(__DELEGATE__)', 1
    rescue SyntaxError
      code  = TEMPLATE % [:_delegate, method_name]
      eval code, binding, '(__DELEGATE__)', 1
      alias_method method_name, :_delegate
      undef_method :_delegate
    end
    private method_name
  end
end