Sha256: e20a1fd3f07183c149561a1b08ce62c135f5df8d7913793db16374656e58a3ec

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

require_relative 'hash_with_indifferent_access'

module Simple
end

class Simple::Hash < Simple::HashWithIndifferentAccess
  VERSION = "1.0.0"

  def method_missing(method_name, *args, &block)
    if keys.map(&:to_s).include?(method_name.to_s) && args.empty? && block.nil?
      fetch(method_name)
    else
      super
    end
  end

  def respond_to_missing?(method_name, include_private = false)
    keys.map(&:to_s).include?(method_name.to_s) || super
  end

  def methods
    super + keys.map(&:to_sym)
  end

  protected

  def convert_value(value, options = {})
    if value.is_a?(Hash)
      Simple::Hash.new(value).freeze
    elsif value.is_a?(Array)
      value.map { |val| convert_value(val, options) }
    else
      value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple-hash-1.0.0 lib/simple/hash.rb