Created
April 8, 2011 01:26
-
-
Save cjheath/909129 to your computer and use it in GitHub Desktop.
An alternative to the builder pattern, e.g. for configuration APIs.
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 Capybara | |
class << self | |
attr_accessor :default_wait_time | |
def magic(a,&b) | |
puts "doing magic for #{a}" | |
yield | |
puts "mischief managed" | |
end | |
def configure &b | |
instance_exec &b | |
end | |
end | |
end | |
Capybara.configure do | |
@default_wait_time = 23 | |
magic "foo" do | |
puts "abra cadabra!" | |
end | |
end | |
p Capybara.default_wait_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment