towry
6/6/2015 - 2:43 PM

sinatra_test.rb

#!/usr/bin/env ruby
# -*- encoding: UTF-8 -*-

class Base
  attr_reader :blocks

  class << self
    def get(path, &block)
      @blocks ||= []
      @blocks << block
    end

    def reset!
      @blocks = []
    end

    def run
      @blocks.each do |bk|
        bk.call
      end
    end
  end

  def self.inherited(subclass)
    subclass.reset!
  end

  reset!
end

class Application < Base
  get '/' do 
    puts "hi"
  end
end

if __FILE__ == $0
  Application.run
end