class Turnout::OrderedOptions

Public Class Methods

new(constructor = {}, &block) click to toggle source
Calls superclass method
# File lib/turnout/ordered_options.rb, line 6
def initialize(constructor = {}, &block)
  if constructor.respond_to?(:to_hash)
    super()
    update(constructor, &block)
    hash = constructor.to_hash

    self.default = hash.default if hash.default
    self.default_proc = hash.default_proc if hash.default_proc
  else
    super()
  end
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/turnout/ordered_options.rb, line 37
def [](key)
  super(key.to_sym)
end
Also aliased as: _get
[]=(key, value) click to toggle source
Calls superclass method
# File lib/turnout/ordered_options.rb, line 33
def []=(key, value)
  super(key.to_sym, value)
end
_get(key)
Alias for: []
except(*keys) click to toggle source
# File lib/turnout/ordered_options.rb, line 58
def except(*keys)
  dup.except!(*keys)
end
except!(*keys) click to toggle source
# File lib/turnout/ordered_options.rb, line 62
def except!(*keys)
  keys.each { |key| delete(key) }
  self
end
method_missing(name, *args) click to toggle source
# File lib/turnout/ordered_options.rb, line 41
def method_missing(name, *args)
  name_string = name.to_s
  if name_string.chomp!('=')
    self[name_string] = args.first
  else
    bangs = name_string.chomp!('!')

    if bangs
      value = fetch(name_string.to_sym)
      raise(RuntimeError.new("#{name_string} is blank.")) if value.nil? || value.empty?
      value
    else
      self[name_string]
    end
  end
end
respond_to_missing?(name, include_private) click to toggle source
# File lib/turnout/ordered_options.rb, line 68
def respond_to_missing?(name, include_private)
  true
end
update(other_hash) { |key, value| ... } click to toggle source
Calls superclass method
# File lib/turnout/ordered_options.rb, line 19
def update(other_hash)
  if other_hash.is_a? Hash
    super(other_hash)
  else
    other_hash.to_hash.each_pair do |key, value|
      if block_given?
        value = yield(key, value)
      end
      self[key] = value
    end
    self
  end
end