Class: Hash
- Includes:
- ActiveSupport::CoreExtensions::Hash::Conversions, ActiveSupport::CoreExtensions::Hash::DeepMerge, ActiveSupport::CoreExtensions::Hash::Diff, ActiveSupport::CoreExtensions::Hash::Except, ActiveSupport::CoreExtensions::Hash::IndifferentAccess, ActiveSupport::CoreExtensions::Hash::Keys, ActiveSupport::CoreExtensions::Hash::ReverseMerge, ActiveSupport::CoreExtensions::Hash::Slice
- Defined in:
- lib/hash.rb,
lib/activesupport-2.2.2/lib/active_support/core_ext/hash.rb
Overview
:nodoc:
Direct Known Subclasses
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
- #method_missing(meth, *args, &block) ⇒ Object
-
#value_of_dotted_property(property) ⇒ Object
in: “foo.bar.baz” out: self.foo.bar.baz == [‘foo’][‘baz’].
Methods included from ActiveSupport::CoreExtensions::Hash::Except
Methods included from ActiveSupport::CoreExtensions::Hash::Slice
Methods included from ActiveSupport::CoreExtensions::Hash::Diff
Methods included from ActiveSupport::CoreExtensions::Hash::Conversions
Methods included from ActiveSupport::CoreExtensions::Hash::ReverseMerge
#reverse_merge, #reverse_merge!
Methods included from ActiveSupport::CoreExtensions::Hash::DeepMerge
Methods included from ActiveSupport::CoreExtensions::Hash::IndifferentAccess
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 |