You See the Invisible Block?

require "rubygems";require "thin";require"markaby"; class Invisible
HTTP_METHODS =[:get,:post,:head,:put,:delete];attr_reader :request,
:response, :params; def initialize(&block); @actions =[]; @with=[];
@layouts={};@views={};;@app=self; instance_eval(
&block) if block end; def action(method, route, &block); @actions<<
[method.to_s, build_route(@with*"/"+route),block] end;HTTP_METHODS.
each{|m|class_eval "def #{m}(r='/',&b); action('#{m}', r, &b) end"}
def with(route); @with.push(route);yield;@with.pop end; def render(
*args,&block);options=args.last.is_a?(Hash)?args.pop: {};@response.
args.last :,@helpers, &(block||@views[
args.last] )).to_s ; content = assigns.merge(
:content => content), @helpers, &layout).to_s if layout; @response.
headers.merge!(options);@response.body=content end;def layout(name=
:default, &block); @layouts[name]=block end; def view(name,&block);
@views[name]=block end; def helpers(&block);@helpers.instance_eval(
&block ) ; instance_eval(&block)  end;  def session;  @request.env[
"rack.session"]end; def use(middleware, *args);
@app,*args) end; def run(*args);Thin::Server.start(@app, *args) end
def call(env); @request =; @response =Rack::; @params = @request.params; if action = recognize(env[
"PATH_INFO"], @params["_method"] ||env["REQUEST_METHOD"]); @params.
merge!(@path_params);;@response.finish; else; [404,
{}, "Not found"]; end; end; def*args,&block);new(&block).
run(*args) end; def;@app|| end;def end; private; def build_route(route);pattern= route.
split("/").inject('\/*') { |r, s| r << (s[0] == ?: ? '(\w+)' : s) +
'\/*' } + '\/*';[/^#{pattern}$/i,route.scan(/\:(\w+)/).flatten] end
def recognize(url, method); method =method.to_s.downcase; @actions.
detect do |m,(pattern,keys),_| method==m&&@path_params=match_route(
pattern,keys,url)end;end;def match_route(pattern,keys,url);matches,
|key,i| params[key]=matches[i]};params;end;end; def method_missing(
method, *args,  &block);  ; if .respond_to?(method) ; send( method, *args, &block);  else; super; end; end



Filed under ruby

6 responses to “You See the Invisible Block?

  1. It’s inbetween


    and here!😛

  2. ; else
    I just got lucky I guess…

  3. Is this one those 3d stereogram, where if you stare long enough an image will appear, only made with ruby code?

    ( 15 mins later )

    Ahh … now I see the lolcat .. I mean invisible block.

  4. it’s a 4d stereogram but you have to stare for 3 days

  5. Got it up and running, I really like it… Nice work!

  6. thx Ben, it should scale a lot better because of it’s shape.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s