Module: HashMethodable
- Included in:
- OpenLibraryEntry
- Defined in:
- lib/fetchworks.rb
Overview
Mixin Module for classes with a hash attribute @data That routes classinstance.method to classinstance.data TODO: infect nested hashes and arrays with this module.
Instance Method Summary collapse
-
#method_missing(method_name, *_args, &_block) ⇒ Object
Expose hash members as methods.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Advertise hash member methods.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args, &_block) ⇒ Object
Expose hash members as methods
25 26 27 28 |
# File 'lib/fetchworks.rb', line 25 def method_missing(method_name, *_args, &_block) key = method_name&.to_s @data&.key?(key) ? @data[key] : nil end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Advertise hash member methods
31 32 33 34 |
# File 'lib/fetchworks.rb', line 31 def respond_to_missing?(method_name, include_private = false) key = method_name&.to_s @data&.key?(key) || super end |