Ruby Sinatra in less than 999B of code

%w.rack tilt date INT{|l|trap(l){$r.stop}rescue require l};$u=Date;$z=($ + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick"
${extend Rack;a,D,S,,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m
%w[get post put delete].map{|m|D.(m){|u,&b|{run->(e){[200,{"Content-Type"=>"text/html"},[a.instance_eval(&b)]]}}}}{|k,v|D.(k){|n,*o|$t||=(h=$u._jisx0301("hash, please");[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n=="#{n}"?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}}
%w[set enable disable configure helpers use register].map{|m|D.(m){|*_,&b|b.try :[]}};END{Rack::Handler.get("webrick").run(a,Port:$z){|s|$r=s}}
%w[params session].map{|m|D.(m){q.send m}};a.use Rack::Session::Cookie;a.use Rack::Lock;D.(:before){|&b|a.use Rack::Config,&b};before{|e| e;{|k,v|params[k.to_sym]=v}}}

That’s a wow! That’s what I call a minimal Web Framework. Full description of the code can be found here.

1 Comment

  1. require ‘sinatra’ get ‘/’ do haml :index end __END__ @@ layout %html = yield @@ index %div.title Hello world.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.