Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move everything inside module, extend rack so we avoid R:: and save a…

… few chars, tnan we can use locals instead of constants and save another char by reusing previously assigned local in top assignment

Signed-off-by: Konstantin Haase <konstantin.mailinglists@googlemail.com>
  • Loading branch information...
commit 86de9a896aefcc412a61ef272a2bc2d117bcb788 1 parent 2abe226
@riffraff riffraff authored committed
Showing with 8 additions and 7 deletions.
  1. +8 −7 almost_sinatra.rb
View
15 almost_sinatra.rb
@@ -1,8 +1,9 @@
%w.rack tilt backports INT TERM..map{|l|trap(l){$r.stop}rescue require l}
-R=Rack;$n=Sinatra=Module.new{A,D,S,$p=R::Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567;Application=A}
-%w[get post put delete].map{|m|D.(m){|u,&b|A.map(u){run->(e){[200,{"Content-Type"=>"text/html"},[A.instance_eval(&b)]]}}}}
-Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v.new(*o){n.to_s==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{R::Handler.get("webrick").run(A,Port:$p){|s|$r=s}}
-%w[params session].map{|m|D.(m){$q.send m}};A.use R::Session::Cookie;A.use R::Lock
-D.(:before){|&b|A.use R::Config,&b};before{|e|$q=R::Request.new e;$q.params.dup.map{|k,v|params[k.to_sym]=v}}
-puts "== Almost #$n/No Version has taken the stage on #$p for development with backup from Webrick"
+$n=Sinatra=Module.new{extend Rack;a,D,S,$p,Application=Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a

This assigns nil to the Application constant, which is not the behaviour the code before had. Pretty sure that's a bug. If it isn't a bug, then you can remove the ",a" on the end of this line, since nil will still be assigned to Application.

a,Application = 1,a # => [1, nil]
a,Application = 1   # => [1, nil]

also note that the following are the same length:

a,Application=1,a
a=1;Application=a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+%w[get post put delete].map{|m|D.(m){|u,&b|a.map(u){run->(e){[200,{"Content-Type"=>"text/html"},[a.instance_eval(&b)]]}}}}
+Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v.new(*o){n.to_s==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{Handler.get("webrick").run(a,Port:$p){|s|$r=s}}
+%w[params session].map{|m|D.(m){$q.send m}};a.use Session::Cookie;a.use Lock
+D.(:before){|&b|a.use Rack::Config,&b};before{|e|$q=Request.new e;$q.params.dup.map{|k,v|params[k.to_sym]=v}}
+puts "== almost #$n/No Version has taken the stage on #$p for development with backup from Webrick"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.