module Demo
attr_accessor :configuration
class Configuration
attr_accessor :public_key, :private_key
def initialize
end
end
def self.configure
yield(self.configuration)
end
def self.configuration
@configuration ||= Configuration.new
end
end
initialize/demo.rb
Demo.configure do |config| config.public_key = 'xxx' config.private_key = 'xxx' end
参考:http://brandonhilkert.com/blog/ruby-gem-configuration-patterns