Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
Created June 14, 2011 06:51
Show Gist options
  • Save matthandlersux/1024440 to your computer and use it in GitHub Desktop.
Save matthandlersux/1024440 to your computer and use it in GitHub Desktop.
confusing scope example in ruby
# this is the usage that confused me:
# it's a different situation than in your example. i had heard someone mention
# that this worked due to dynamic scoping, but after looking into it, it's actually achieved
# with reflection. glad we figured this out. hifive! o/ \o
require 'sinatra'
helpers do
def login
@user = "test"
yield
end
end
# go to http://localhost:4567/, it will return "test"
get "/" do
login do
return @user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment