Skip to content

Instantly share code, notes, and snippets.

def debug_line(*list)
ret = "Debug: "
0.step(list.length, 2) do |x|
label, value = list[x,x+1]
ret += "#{label} = '#{value}', "
end
puts ret
end
debug_line("a", 10, "b", 20)
require 'rubygems'
require 'sinatra'
data = "none"
before do
content_type 'text/plain', :charset => 'utf-8'
request.env['PATH_INFO'].gsub!(/\/$/,'')
end
tog_data = "house"
get '/one/:word' do
tog_data = "mouse" # This works and sets tog_data to "mouse"
end
get '/two/:word' do
tog_data = params[:word] # This does not work, tog_data becomes private
end
# I've been playing around with Sinatra for a short while.
# I had heard that it was possible to maintain things like
# persistent database connections, etc. I became curious if
# it would be possible to share a variable between clients
# accessing my Sinatra app. I was especially interested in
# how this interacted and differed from the sessions variable
# available with enable :sessions and I like to poke around
# in things. I've been told that I should never attempt to
# use a global-like variable in rack/rails/sinatra and while
# it may be a very bad way to do things, it may still have
#!/bin/sh
# This test script assumes the app is being run with
# `ruby sinatra_shared_variable_test.rb' on localhost
# port 4567.
# You can change this to your preferred automated http dump command
testapp='wget -q -O -'
$testapp http://localhost:4567/one