Class: ConfigMapper::ObjectAsHash
- Inherits:
-
Object
- Object
- ConfigMapper::ObjectAsHash
- Defined in:
- lib/config_mapper/object_as_hash.rb
Overview
Wrap an object to make it look more like a Hash.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(target) ⇒ ObjectAsHash
constructor
A new instance of ObjectAsHash.
Constructor Details
#initialize(target) ⇒ ObjectAsHash
Returns a new instance of ObjectAsHash.
15 16 17 |
# File 'lib/config_mapper/object_as_hash.rb', line 15 def initialize(target) @target = target end |
Class Method Details
.[](target) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/config_mapper/object_as_hash.rb', line 7 def self.[](target) if target.is_a?(Hash) target else ObjectAsHash.new(target) end end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 |
# File 'lib/config_mapper/object_as_hash.rb', line 19 def [](key) @target.public_send(key) end |
#[]=(key, value) ⇒ Object
23 24 25 |
# File 'lib/config_mapper/object_as_hash.rb', line 23 def []=(key, value) @target.public_send("#{key}=", value) end |