Skip to content

Instantly share code, notes, and snippets.

@mbleigh
Created April 23, 2009 03:09
Show Gist options
  • Save mbleigh/100269 to your computer and use it in GitHub Desktop.
Save mbleigh/100269 to your computer and use it in GitHub Desktop.
# 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