class MDT::DataStorage
Implements a singleton key-value data storage to be used across MDT
. Uses a bit of metaprogramming for ease of use.
Public Class Methods
new()
click to toggle source
Initializes the storage with empty Hash.
# File lib/mdt/data_storage.rb 9 def initialize 10 @storage = {} 11 end
Public Instance Methods
method_missing(m, *args, &block)
click to toggle source
Override method_missing
to delegate to the storage hash.
# File lib/mdt/data_storage.rb 14 def method_missing(m, *args, &block) 15 if /^(\w+)=$/ =~ m 16 @storage[$1.to_sym] = args[0] 17 else 18 @storage[m.to_sym] 19 end 20 end
respond_to?(method_name, include_private = false)
click to toggle source
Override respond_to? to always return true as it always delegates to the hash.
# File lib/mdt/data_storage.rb 23 def respond_to?(method_name, include_private = false) 24 true 25 end