class Fastball::HashDot
A utility class to allow referencing nested hash values as chained method calls.
Example¶ ↑
!!! ruby> h = Fastball::HashDot.new name: { name: 'Jordan', state: 'Texas' } ruby> h.contact.name => "Jordan" ruby> h.contact.state => "Texas"
Public Class Methods
new(hash={})
click to toggle source
# File lib/fastball/hash_dot.rb, line 16 def initialize(hash={}) @hash = {} hash.map do |k, v| @hash[k.to_s] = if v.kind_of?(Hash) self.class.new v else @hash[k.to_s] = v end end end
Private Instance Methods
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/fastball/hash_dot.rb, line 30 def method_missing(method_name, *args, &block) @hash[method_name.to_s] || super end
respond_to_missing?(method_name, include_private=false)
click to toggle source
Calls superclass method
# File lib/fastball/hash_dot.rb, line 34 def respond_to_missing?(method_name, include_private=false) @hash.key?(method_name.to_s) || super end