Class: Reality::BaseElement

Inherits:
Object
  • Object
show all
Defined in:
lib/reality/base_element.rb

Overview

Base class used for elements configurable via options

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ BaseElement

Returns a new instance of BaseElement.

Yields:

  • (_self)

Yield Parameters:



19
20
21
22
# File 'lib/reality/base_element.rb', line 19

def initialize(options = {})
  self.options = options
  yield self if block_given?
end

Instance Method Details

#options=(options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/reality/base_element.rb', line 24

def options=(options)
  options.each_pair do |k, v|
    keys = k.to_s.split('.')
    target = self
    keys[0, keys.length - 1].each do |target_accessor_key|
      target = target.send target_accessor_key.to_sym
    end
    begin
      target.send "#{keys.last}=", v
    rescue NoMethodError
      raise "Attempted to configure property \"#{keys.last}\" on #{self.class} but property does not exist."
    end
  end
end