public
Created

An alternative to the builder pattern, e.g. for configuration APIs.

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.