Class: MDT::DataStorage
- Inherits:
-
Object
- Object
- MDT::DataStorage
- Includes:
- Singleton
- Defined in:
- lib/mdt/data_storage.rb
Overview
Implements a singleton key-value data storage to be used across MDT. Uses a bit of metaprogramming for ease of use.
Instance Method Summary collapse
-
#initialize ⇒ DataStorage
constructor
Initializes the storage with empty Hash.
-
#method_missing(m, *args, &block) ⇒ Object
Override method_missing to delegate to the storage hash.
-
#respond_to?(method_name, include_private = false) ⇒ Boolean
Override respond_to? to always return true as it always delegates to the hash.
Constructor Details
#initialize ⇒ DataStorage
Initializes the storage with empty Hash.
9 10 11 |
# File 'lib/mdt/data_storage.rb', line 9 def initialize @storage = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Override method_missing to delegate to the storage hash.
14 15 16 17 18 19 20 |
# File 'lib/mdt/data_storage.rb', line 14 def method_missing(m, *args, &block) if /^(\w+)=$/ =~ m @storage[$1.to_sym] = args[0] else @storage[m.to_sym] end end |
Instance Method Details
#respond_to?(method_name, include_private = false) ⇒ Boolean
Override respond_to? to always return true as it always delegates to the hash.
23 24 25 |
# File 'lib/mdt/data_storage.rb', line 23 def respond_to?(method_name, include_private = false) true end |