Class: EacRubyUtils::Struct
Instance Method Summary
collapse
Constructor Details
#initialize(initial_data = {}) ⇒ Struct
Returns a new instance of Struct.
8
9
10
|
# File 'lib/eac_ruby_utils/struct.rb', line 8
def initialize(initial_data = {})
self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
22
23
24
|
# File 'lib/eac_ruby_utils/struct.rb', line 22
def method_missing(method_name, *arguments, &block)
property_method?(method_name) ? fetch(method_name) : super
end
|
Instance Method Details
12
13
14
15
|
# File 'lib/eac_ruby_utils/struct.rb', line 12
def [](key)
key, bool = parse_key(key)
bool ? self[key].present? : data[key]
end
|
#fetch(key) ⇒ Object
17
18
19
20
|
# File 'lib/eac_ruby_utils/struct.rb', line 17
def fetch(key)
key, bool = parse_key(key)
bool ? fetch(key).present? : data.fetch(key)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
26
27
28
|
# File 'lib/eac_ruby_utils/struct.rb', line 26
def respond_to_missing?(method_name, include_private = false)
property_method?(method_name) || super
end
|
30
31
32
|
# File 'lib/eac_ruby_utils/struct.rb', line 30
def to_h
data.dup
end
|