Created
April 23, 2009 03:09
-
-
Save mbleigh/100269 to your computer and use it in GitHub Desktop.
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
# OptionsProxy creates a proxy object with attribute accessors | |
# and defaults. | |
options = OptionsProxy.new(:fancy, :name, { | |
:fancy => true | |
}) | |
options.fancy # => true | |
options.name # => nil | |
options.name = 'Dirt' | |
options.name # => 'Dirt' | |
options.fancy = false | |
options.set {:name => 'Gold', :fancy => true} | |
options.name # => 'Gold' | |
options.fancy # => true | |
# It would also have a factory interface | |
options = OptionsFactory do |o| | |
o.fancy true | |
o.name | |
end | |
options # => equivalent to the above example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment