|
|
找到开始:
module Sinatra class Application < Base puts "aaaaa" # we assume that the first file that requires 'sinatra' is the # app_file. all other path related options are calculated based # on this path by default. set :app_file, caller_files.first || $0 set :run, Proc.new { $0 == app_file } if run? && ARGV.any? require 'optparse' OptionParser.new { |op| op.on('-x') { set :lock, true } op.on('-e env') { |val| set :environment, val.to_sym } op.on('-s server') { |val| set :server, val } op.on('-p port') { |val| set :port, val.to_i } op.on('-o addr') { |val| set :bind, val } }.parse!(ARGV.dup) end end at_exit { Application.run! if $!.nil? && Application.run? }en
首先看看at_exit.....
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_m_kernel.html#Kernel.at_exit
其实就是跑Sinatra.Base.run
经常用set,看一下:
# Sets an option to the given value. If the value is a proc, # the proc will be called every time the option is accessed. def set(option, value = (not_set = true), &block) raise ArgumentError if block and !not_set value = block if block if value.kind_of?(Proc) metadef(option, &value) metadef("#{option}?") { !!__send__(option) } metadef("#{option}=") { |val| metadef(option, &Proc.new{val}) } elsif not_set raise ArgumentError unless option.respond_to?(:each) option.each { |k,v| set(k, v) } elsif respond_to?("#{option}=") __send__ "#{option}=", value else set option, Proc.new{value} end self end |
|