Sha256: 3e9a9ea8afeeba3342f0c9ca41e7f59f54c53b65fb453255c391f5d25a3102e9

Contents?: true

Size: 1.2 KB

Versions: 20

Compression:

Stored size: 1.2 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)
     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

20 entries across 20 versions & 1 rubygems

Version Path
lazier-2.6.7 lib/lazier/hash.rb
lazier-2.6.6 lib/lazier/hash.rb
lazier-2.6.5 lib/lazier/hash.rb
lazier-2.6.4 lib/lazier/hash.rb
lazier-2.6.3 lib/lazier/hash.rb
lazier-2.6.2 lib/lazier/hash.rb
lazier-2.6.1 lib/lazier/hash.rb
lazier-2.6.0 lib/lazier/hash.rb
lazier-2.5.3 lib/lazier/hash.rb
lazier-2.5.2 lib/lazier/hash.rb
lazier-2.5.1 lib/lazier/hash.rb
lazier-2.5.0 lib/lazier/hash.rb
lazier-2.4.0 lib/lazier/hash.rb
lazier-2.3.1 lib/lazier/hash.rb
lazier-2.3.0 lib/lazier/hash.rb
lazier-2.2.0 lib/lazier/hash.rb
lazier-2.1.1 lib/lazier/hash.rb
lazier-2.1.0 lib/lazier/hash.rb
lazier-2.0.0 lib/lazier/hash.rb
lazier-1.0.7 lib/lazier/hash.rb