def configure(&block) @config ||= Configuration.new block.call(@config) end configure do |config| config.use :yaml end
みたいなのが、Object#instance_execを使うとスッキリ書ける。
def configure(&block) @config ||= Configuration.new @config.instance_exec(&block) end configure do use :yaml end
ブロックの中のレシーバがinstance_exec
のレシーバになる。