Class: Embargoed::InheritableOptions

Inherits:
OrderedOptions show all
Defined in:
lib/embargoed/ordered_options.rb

Overview

InheritableOptions provides a constructor to build an OrderedOptions hash inherited from another hash.

Use this if you already have some hash and you want to create a new one based on it.

h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
h.girl # => 'Mary'
h.boy  # => 'John'

Instance Method Summary collapse

Methods inherited from OrderedOptions

#[], #[]=, #except, #except!, #method_missing, #respond_to_missing?, #update

Constructor Details

#initialize(parent = nil) ⇒ InheritableOptions

Returns a new instance of InheritableOptions.



83
84
85
86
87
88
89
90
91
92
# File 'lib/embargoed/ordered_options.rb', line 83

def initialize(parent = nil)
  if parent.kind_of?(Embargoed::OrderedOptions)
    # use the faster _get when dealing with OrderedOptions
    super(parent) {|key,value| parent._get(key) }
  elsif parent
    super(parent) { |key, value| parent[key] }
  else
    super(parent)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Embargoed::OrderedOptions

Instance Method Details

#inheritable_copyObject



94
95
96
# File 'lib/embargoed/ordered_options.rb', line 94

def inheritable_copy
  self.class.new(self)
end