mbleigh (owner)

Revisions

gist: 100269 Download_button fork
public
Public Clone URL: git://gist.github.com/100269.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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