Created
April 7, 2011 10:44
-
-
Save bgswan/907530 to your computer and use it in GitHub Desktop.
Scottish Ruby Conference tutorial exercise
This file contains 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
class AppServerConfiguration | |
attr_accessor :port, :admin_password | |
end | |
class Configuration | |
attr_accessor :tail_logs, :max_connections, :admin_password | |
def initialize(block) | |
block.call(self) | |
end | |
def app_server | |
@app_server ||= AppServerConfiguration.new | |
yield @app_server if block_given? | |
@app_server | |
end | |
end | |
def configure(&block) | |
Configuration.new(block) | |
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