Class: Seam::DeepHashAccessor
- Inherits:
-
Object
- Object
- Seam::DeepHashAccessor
- Defined in:
- lib/seam/deep_hash_accessor.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(data) ⇒ DeepHashAccessor
constructor
A new instance of DeepHashAccessor.
- #to_h ⇒ Object
Constructor Details
#initialize(data) ⇒ DeepHashAccessor
Returns a new instance of DeepHashAccessor.
7 8 9 10 |
# File 'lib/seam/deep_hash_accessor.rb', line 7 def initialize(data) @data = data create_accessor_methods end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/seam/deep_hash_accessor.rb', line 12 def [](key) # Subscript access is Hash-like and returns nil for unknown keys, while # method access continues to raise NoMethodError. name = key.to_s return nil unless respond_to?(name) public_send(name) end |
#to_h ⇒ Object
21 22 23 |
# File 'lib/seam/deep_hash_accessor.rb', line 21 def to_h @data end |