Class: Fusu::InheritableOptions

Inherits:
OrderedOptions show all
Defined in:
lib/fusu/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'

Direct Known Subclasses

Configurable::Configuration

Instance Method Summary collapse

Methods inherited from OrderedOptions

#[], #[]=, #method_missing, #respond_to_missing?

Constructor Details

#initialize(parent = nil) ⇒ InheritableOptions

Returns a new instance of InheritableOptions.



68
69
70
71
72
73
74
75
76
77
# File 'lib/fusu/ordered_options.rb', line 68

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

Dynamic Method Handling

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

Instance Method Details

#inheritable_copyObject



79
80
81
# File 'lib/fusu/ordered_options.rb', line 79

def inheritable_copy
  self.class.new(self)
end