Sha256: 07176932caea8648de0e431ef845d2d9ab3cad5bc869f5a574277d340475d9ee

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8
#
# This file is part of the lazier gem. Copyright (C) 2012 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)
     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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lazier-1.0.6 lib/lazier/hash.rb
lazier-1.0.5 lib/lazier/hash.rb
lazier-1.0.4 lib/lazier/hash.rb
lazier-1.0.3 lib/lazier/hash.rb
lazier-1.0.2 lib/lazier/hash.rb
lazier-1.0.1 lib/lazier/hash.rb