Module: GlimR::Configurable

Included in:
SceneObject
Defined in:
lib/glimr/configurable.rb

Overview

Hash-configurable object. Takes a hash and sets the setters named by the keys to the values. Use #default_config to define the default config.

class MyConfigurable
  include Configurable
  attr_accessor :x, :y
  def default_config
    { :x => 'default x', :y => 'default y' }
  end
end

mc = MyConfigurable.new :y => 6
mc.x
# => 'default x'
mc.y
# => 6

Instance Method Summary collapse

Instance Method Details

#default_configObject



31
32
33
# File 'lib/glimr/configurable.rb', line 31

def default_config
  {}
end

#initialize(config_hash = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
28
29
# File 'lib/glimr/configurable.rb', line 24

def initialize(config_hash = {}, &optional_config_block)
  config = default_config.merge(config_hash)
  config.each{|k,v| instance_variable_set("@#{k}", v) }
  super
  yield(self) if block_given?
end