Sha256: 28f3b9042e21c81930a0efa0181c52c183568a38f2af282c9b5f9e2646381610

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8
#
# This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

module Lazier
  # Extensions for Hash objects.
  module Hash
    extend ::ActiveSupport::Concern

    # This is called when the user access a member using dotted notation.
    #
    # @param method [String|Symbol] Key to search.
    # @param args [Array] *Unused.*
    # @param block [Proc] *Unused.*
    # @return [Object] The value for the key.
    def method_missing(method, *args, &block)
     if self.has_key?(method.to_sym) then
        self[method.to_sym]
     elsif self.has_key?(method.to_s) then
        self[method.to_s]
     else
        ::Hash.method_missing(method, *args, &block)
     end
    end

    # This is called when the user access a member using dotted notation.
    #
    # @param method [String|Symbol] Key to search.
    # @return [Boolean] `true` if the key exists, `false` otherwise.
    def respond_to?(method)
      (self.has_key?(method.to_sym) || self.has_key?(method.to_s)) ? true : ::Hash.respond_to?(method)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lazier-2.8.1 lib/lazier/hash.rb
lazier-2.8.0 lib/lazier/hash.rb
lazier-2.7.0 lib/lazier/hash.rb