Class: Hash

Overview

:nodoc:

Direct Known Subclasses

HashWithIndifferentAccess

Constant Summary

Constants included from ActiveSupport::CoreExtensions::Hash::Conversions

ActiveSupport::CoreExtensions::Hash::Conversions::XML_FORMATTING, ActiveSupport::CoreExtensions::Hash::Conversions::XML_PARSING, ActiveSupport::CoreExtensions::Hash::Conversions::XML_TYPE_NAMES

Instance Method Summary collapse

Methods included from ActiveSupport::CoreExtensions::Hash::Except

#except, #except!

Methods included from ActiveSupport::CoreExtensions::Hash::Slice

#slice, #slice!

Methods included from ActiveSupport::CoreExtensions::Hash::Diff

#diff

Methods included from ActiveSupport::CoreExtensions::Hash::Conversions

included, #to_query, #to_xml

Methods included from ActiveSupport::CoreExtensions::Hash::ReverseMerge

#reverse_merge, #reverse_merge!

Methods included from ActiveSupport::CoreExtensions::Hash::DeepMerge

#deep_merge, #deep_merge!

Methods included from ActiveSupport::CoreExtensions::Hash::IndifferentAccess

#with_indifferent_access

Methods included from ActiveSupport::CoreExtensions::Hash::Keys

#assert_valid_keys, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



3
4
5
6
7
# File 'lib/hash.rb', line 3

def method_missing(meth, *args, &block)
  if args.size == 0
    self[meth.to_s] || self[meth.to_sym]
  end
end

Instance Method Details

#value_of_dotted_property(property) ⇒ Object

in: “foo.bar.baz” out: self.foo.bar.baz == [‘foo’][‘baz’]



11
12
13
14
15
16
17
18
19
# File 'lib/hash.rb', line 11

def value_of_dotted_property(property)
  methods = property.split('.')
  # call each method in the dotted chain until we get to the result
  hash = self
  methods.each do |method|
    hash = hash.send(method)
  end
  hash
end