Where do I put code in Sinatra (ruby web framework) that I just want to execute once?

Require 'rubygems' require 'sinatra' set :my_variable, "world" get '/' do " My_variable end.

I guess, I'm confused about the purpose of a Sinatra config block versus doing something outside of a block. – Corey Trager Nov 28 '09 at 15:02 2 Options are application level settings while configuration allows you to customize the behavior according to current environment. – Simone Carletti Nov 28 '09 at 15:08 configure is just a block of code which will be executed once.

– Yoann Le Touche Dec 1 '09 at 14:29.

One other way is : require 'rubygems' require 'sinatra' @my_variable="world" get '/' do ".

I would set a class variable — eg. @@my_variable — inside the configure block. The configure block exists for code you want to run at start up, so setting your variable their makes sense. Your Sinatra application is a subclass of Sinatra::Base, so using a class variable in this situation seems appropriate.

Configure block is just to app configuration related. If that's what it is, you should encapsulate it proper: require 'sinatra' configure do set :my_option, "world" end get '/' do " My_option}" end.

I put in f. I put at m. I put code in Sinatra that I.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions