Sha256: c27edd731ba20e1804d14546f81b3724504e28f0e0af55496489c00c062f6f4e

Contents?: true

Size: 434 Bytes

Versions: 1

Compression:

Stored size: 434 Bytes

Contents

require 'hashie'

class HashExtractor
  attr_reader :parent

  def initialize(value, parent)    
    @value = to_string_access(value)
    @parent = parent
  end

  def [](symbol)
    if @value.has_key? symbol
      @value[symbol]
    else
      @parent[symbol]
    end
  end

  private
  def to_string_access(hash)
    hash.dup.tap do |hash|
      hash.extend Hashie::HashExtensions
      hash.hashie_stringify_keys!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
musterb-0.0.1 lib/musterb/hash_extractor.rb