Skip to content

Instantly share code, notes, and snippets.

@rondinif
Created April 29, 2013 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondinif/5481120 to your computer and use it in GitHub Desktop.
Save rondinif/5481120 to your computer and use it in GitHub Desktop.
sample_app.rb
# singleton-as-module loaded once, kept in memory
module App
module Global extend self
def calc
@calc ||= StatefulCalculator.new
end
end
end
App::Global.calc.turn_on # It's possibile to call a method to load data in the statefull java object
class Sample < Sinatra::Base
get '/' do
"Welcome, calculator register:#{App::Global.calc.display}"
end
get '/add_one' do
"added one to calculator register, new value:#{App::Global.calc.add(1)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment