Created
June 14, 2011 06:51
-
-
Save matthandlersux/1024440 to your computer and use it in GitHub Desktop.
confusing scope example in ruby
This file contains 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
# 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