Created
April 29, 2013 11:47
-
-
Save rondinif/5481120 to your computer and use it in GitHub Desktop.
sample_app.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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