Module: Shipping::HashMethodAccess

Defined in:
app/services/shipping/hash_method_access.rb

Overview

Gives a plain Hash attribute-style read access (response.success?,
response.rates) so shipping adapters can hand callers a response hash
that quacks like an object. extend a response hash with this instead of
defining singleton method_missing on it — YARD can't document
def obj.method_missing ("Undocumentable method defined on object
instance"), and the one-liner keeps every adapter consistent.

response = { success: true, rates: [] }
response.extend(Shipping::HashMethodAccess)
response.success? # => true

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



15
16
17
# File 'app/services/shipping/hash_method_access.rb', line 15

def method_missing(name, *args)
  key?(name) ? self[name] : super
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/services/shipping/hash_method_access.rb', line 19

def respond_to_missing?(name, include_private = false)
  key?(name) || super
end