Skip to content

Instantly share code, notes, and snippets.

@paulcc
Created April 7, 2011 10:57
Show Gist options
  • Save paulcc/907556 to your computer and use it in GitHub Desktop.
Save paulcc/907556 to your computer and use it in GitHub Desktop.
another block exercise
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
class AppServerConfig
attr_accessor :port, :admin_password
end
def app_server
yield(@app_server ||= AppServerConfig.new) if block_given?
@app_server
end
end
def configure
yield(c = Configuration.new)
c
end
configuration = configure do |config|
config.tail_logs = true
config.max_connections = 55
config.admin_password = 'secret'
config.app_server do |app_server_config|
app_server_config.port = 8808
app_server_config.admin_password = config.admin_password
end
end
configuration.class # => Configuration
configuration.tail_logs # => true
configuration.app_server.admin_password # => 'secret'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment