Gem 自己写一个 lib 或者 gem,附带 config 的模版类

mr_night · 2016年05月24日 · 1379 次阅读
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

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号