Created
March 26, 2009 12:11
-
-
Save ijonas/86057 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AppServerConfig | |
attr_accessor :port, :admin_password | |
end | |
class Configuration | |
attr_accessor :tail_logs, :max_connections, :admin_password | |
def initialize | |
@app_server_config = AppServerConfig.new | |
end | |
def app_server # &another_block | |
if block_given? | |
yield @app_server_config | |
else | |
@app_server_config | |
end | |
end | |
end | |
def configure # &block | |
configuration_class = Configuration.new | |
yield configuration_class | |
configuration_class | |
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 | |
p configuration.class # => Configuration | |
p configuration.tail_logs # => true | |
p configuration.app_server.admin_password # => 'secret' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment