Sha256: b7800105209ee3c837a25a166a4987ce997cb967acb2366724a49df2aab2cb08

Contents?: true

Size: 652 Bytes

Versions: 1

Compression:

Stored size: 652 Bytes

Contents

module Loquor
  class Representation
    def initialize(hash)
      @hash = hash
    end

    def ==(other)
      if other.is_a?(Representation)
        @hash == other.get_instance_variable(:@hash)
      elsif other.is_a?(Hash)
        @hash == other
      else
        false
      end
    end

    def [](key)
      @hash[key]
    end

    def method_missing(name, *args)
      if @hash.has_key?(name)
        @hash[name]
      else
        super
      end
    end
  end
end

class Hash
  alias_method :hash_equals, :==
  def ==(other)
    if other.is_a?(Loquor::Representation)
      other == self
    else
      hash_equals(other)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
loquor-0.1.2 lib/loquor/representation.rb