Sha256: bc3c11380f3f377e67b36afd41cf37b4da3b6d4b8a23d04e6573b75039807c4d

Contents?: true

Size: 412 Bytes

Versions: 1

Compression:

Stored size: 412 Bytes

Contents

class RecursiveClosedStruct
  def initialize(hash)
    @hash = hash
  end

  def has_key?(key)
    @hash.has_key? key
  end

  def method_missing(name, *)
    value = fetch(name)
    if value.is_a?(Hash)
      self.class.new(value)
    else
      value
    end
  end

  private

  def fetch(name)
    @hash.fetch(name) do
      raise NoMethodError.new("undefined method `#{name}' for #{self}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prawn_cocktail-0.7.1 lib/prawn_cocktail/utils/recursive_closed_struct.rb