Method: Experiment::Config.get

Defined in:
lib/experiment/config.rb

.get(key) ⇒ Object .get(key, default) ⇒ Object .get(key, default = nil, interpolations) ⇒ Object

Allows access to any config option by key. Supports Interploations. Interpolations are supported as opts argument

Words preceded with a colon (:) are interpolated

Examples:

Config.get :existing                   #=> "hello :what"
Config.get :non_existent, "hello"      #=> "hello"
Config.get :exisitng, :what => "world" #=> "hello world"

Overloads:

  • .get(key) ⇒ Object

    Same as [].

  • .get(key, default) ⇒ Object

    Returns default if key not found in configuration.

  • .get(key, default = nil, interpolations) ⇒ Object

    Interpolates values preceded by semicolon. Otionaly second argument may be a default value to use if option not present.

    Parameters:

    • interpolations (Hash)

      key will be replaced by value.



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/experiment/config.rb', line 104

def get(v, *opts)
  @used ||= []
    @used << v.to_s
  default = opts.shift if opts.length == 2 || !opts.first.is_a?(Hash)
  out = @config[v.to_s] || default
  if opts = opts.first
      opts.keys.reduce(out.dup) do |result, inter|
        result.gsub /:#{inter}/, opts[inter]
      end
    else
    out
 end
end