Module: Coach4rb::Mixin::AutoConstructor::InstanceMethods
- Defined in:
- lib/coach4rb/mixin/auto_constructor.rb
Instance Method Summary (collapse)
-
- (Object) [](key)
Provides hash-like access on the properties of this object.
-
- (Object) []=(key, value)
Provides hash-like access on the properties of this object.
-
- (Object) initialize(a_hash = {})
Creates a object using the keys and values given in the hash.
Instance Method Details
- (Object) [](key)
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 |
- (Object) []=(key, value)
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 |
- (Object) initialize(a_hash = {})
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 |