Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Created February 1, 2011 06:25
Show Gist options
  • Save jwreagor/805505 to your computer and use it in GitHub Desktop.
Save jwreagor/805505 to your computer and use it in GitHub Desktop.
Example of variable re-evaluation after setter usage in ConfigSet.
# 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'
@jwreagor
Copy link
Author

jwreagor commented Feb 1, 2011

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.

@jwreagor
Copy link
Author

jwreagor commented Feb 1, 2011

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