Class: Middleman::CoreExtensions::Data::Proxies::HashProxy

Inherits:
BaseProxy
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb

Instance Attribute Summary

Attributes inherited from BaseProxy

#accessed_keys, #depth

Instance Method Summary collapse

Methods inherited from BaseProxy

#_replace_parent, #_top, #as_json, #initialize

Constructor Details

This class inherits a constructor from Middleman::CoreExtensions::Data::Proxies::BaseProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object



21
22
23
24
25
26
27
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb', line 21

def method_missing(name, *_args)
  return self[name] if @data.key?(name)

  super
rescue NoMethodError
  nil
end

Instance Method Details

#[](key) ⇒ Object Also known as: get



12
13
14
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb', line 12

def [](key)
  wrap_data key.to_sym, @data[key]
end

#fetch(key, default = Undefined, &block) ⇒ Object



8
9
10
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb', line 8

def fetch(key, default = Undefined, &block)
  wrap_data key.to_sym, @data.fetch(key, default, &block)
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/hash.rb', line 17

def respond_to_missing?(name, *)
  @data.key?(name) || super
end