getやpost等をmethodとして呼び出す
methodsの中をpで見たら"GET /count"等があったので、callしてみたらふつうにwebブラウザでアクセスした時にうけとる文字列が返ってきた。erb等が使われている場合はerbを通した後の文字列(html)が返ってきた。
require 'rubygems' require 'sinatra' require 'rack' @@arr = [1,2,3,4,5] get '/' do p methods @count = method('GET /count').call @sum = method('GET /sum').call "count:#{@count}, sum:#{@sum}<br /> #{methods.join('<br />')}" end get '/count' do @@arr.size.to_s end get '/sum' do @@arr.inject{|a,b|a+b}.to_s end
count:5, sum:15 GET / attachment haml mime_type response methods send response= taint instance_variable_defined? HEAD / send_file sass body singleton_methods instance_eval forward back last_modified redirect nil? GET /count options erb etag __tilt__ protected_methods instance_exec display to_yaml tainted? method session untaint instance_of? HEAD /count equal? less hash call error private_methods kind_of? freeze params GET /sum cache_control eql? id builder params= app env public_methods app= env= object_id is_a? to_yaml_properties content_type HEAD /sum tap type not_found instance_variables __id__ frozen? to_enum request call! to_a respond_to? request= class settings taguri GET /__sinatra__/:image.png halt instance_variable_get pass == __send__ taguri= === enum_for expires extend to_s status clone to_yaml_style HEAD /__sinatra__/:image.png =~ instance_variable_set erubis headers inspect dup