Created
February 1, 2011 06:25
-
-
Save jwreagor/805505 to your computer and use it in GitHub Desktop.
Example of variable re-evaluation after setter usage in ConfigSet.
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
# Set some values... | |
config = ConfigSet.for('routes') { | |
host "codeforpeople.com" | |
port 80 | |
signup_url "http://#{ host }/signup" | |
signout_url "http://#{ port }/signout" | |
app { | |
signup_url "http://#{ host }/signup" | |
} | |
} | |
# Current values... | |
config.host.should == "codeforpeople.com" | |
config.signup_url.should == "http://codeforpeople.com/signup" | |
# Reset host using it's setter outside of the block. | |
config.host = "apple.com" | |
# Now this is true... | |
config.host.should == "apple.com" | |
# Child re-evaluates because config.host changed!!! | |
config.signup_url.should == "http://apple.com/signup" | |
# Of course this is left untouched since it doesn't use config.host... | |
config.signout_url.should == "http://80/signout" | |
# Nested values are untouched as well, because they are out of scope. | |
# Though I guess I could allow it, the code's there it's just blocked. | |
config.app.signup_url.should == "http://codeforpeople.com/signup" | |
config.app.host.should == 'codeforpeople.com' |
It also increases the line number of the class by like 20 to 75 lines of total code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I swear to god this works and it was pretty easy once I got the logic right. I'm just not sure how useful it is or if I'll include it.