Skip to content

Instantly share code, notes, and snippets.

@seesmith
Created April 7, 2011 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seesmith/907587 to your computer and use it in GitHub Desktop.
Save seesmith/907587 to your computer and use it in GitHub Desktop.
Scottish Ruby Conference Tutorial No 2 I&I
class Configuration
attr_accessor :tail_logs
attr_accessor :max_connections
attr_accessor :admin_password
attr_accessor :app_server
def initialize
@app_server = AppServer.new
end
def app_server
yield @app_server if block_given?
@app_server
end
end
class AppServer
attr_accessor :port
attr_accessor :admin_password
end
def configure
x = Configuration.new
yield x if block_given?
x
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
puts configuration.class # => Configuration
puts configuration.tail_logs # => true
puts configuration.app_server.admin_password # => 'secret'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment