Sha256: 8583e0514422fbbbdc20f133602d1b77208d725d65ab7f8e919438adb7988474

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
#
# This file is part of the cowtech-extensions gem. Copyright (C) 2011 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 Cowtech
	module Extensions
    # 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)
       rv = nil

       if self.has_key?(method.to_sym) then
          rv = self[method.to_sym]
       elsif self.has_key?(method.to_s) then
          rv = self[method.to_s]
       else
          rv = ::Hash.method_missing(method, *args, &block)
       end

       rv
			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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cowtech-extensions-2.7.4 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.7.3 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.7.2 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.7.1 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.7.0 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.6.0 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.5.1 lib/cowtech-extensions/hash.rb
cowtech-extensions-2.5.0 lib/cowtech-extensions/hash.rb