Module: Coach4rb::Mixin::AutoConstructor::InstanceMethods
- Defined in:
- lib/coach4rb/mixin/auto_constructor.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Provides hash-like access on the properties of this object.
-
#[]=(key, value) ⇒ Object
Provides hash-like access on the properties of this object.
-
#initialize(a_hash = {}) ⇒ Object
Creates a object using the keys and values given in the hash.
Instance Method Details
#[](key) ⇒ Object
Provides hash-like access on the properties of this object.
49 50 51 52 53 54 55 |
# File 'lib/coach4rb/mixin/auto_constructor.rb', line 49 def [](key) if value = instance_variable_get("@#{key}") value else send key rescue nil end end |
#[]=(key, value) ⇒ Object
Provides hash-like access on the properties of this object.
61 62 63 |
# File 'lib/coach4rb/mixin/auto_constructor.rb', line 61 def []=(key,value) instance_variable_set("@#{key}",value) end |
#initialize(a_hash = {}) ⇒ Object
Creates a object using the keys and values given in the hash.
Parameters:
38 39 40 41 42 43 |
# File 'lib/coach4rb/mixin/auto_constructor.rb', line 38 def initialize(a_hash={}) raise 'Param a_hash is not a hash!' unless a_hash.is_a? Hash a_hash.each do |key, value| instance_variable_set("@#{key}", value) end end |