class Loquor::ObjectHash

Public Class Methods

new(hash, options = {}) click to toggle source
# File lib/loquor/object_hash.rb, line 6
def initialize(hash, options = {})
  @hash = hash
  @strict = options[:strict]
end

Public Instance Methods

==(other) click to toggle source
# File lib/loquor/object_hash.rb, line 11
def ==(other)
  if other.is_a?(ObjectHash)
    @hash == other.get_instance_variable(:@hash)
  elsif other.is_a?(Hash)
    @hash == other
  else
    false
  end
end
[](key) click to toggle source
# File lib/loquor/object_hash.rb, line 21
def [](key)
  fetch_indescriminately(key)
rescue ObjectHashKeyMissingError
  if @strict
    raise $!
  else
    nil
  end
end
method_missing(name, *args) click to toggle source
# File lib/loquor/object_hash.rb, line 31
def method_missing(name, *args)
  if name[-1] == "="
    @hash.send(name, *args) 
  else
    self[name]
  end
end
respond_to?(key) click to toggle source
Calls superclass method
# File lib/loquor/object_hash.rb, line 39
def respond_to?(key)
  return true if super
  @hash.has_key?(key.to_s) || @hash.has_key?(key.to_sym)
end

Private Instance Methods

fetch_indescriminately(name, *args) click to toggle source
# File lib/loquor/object_hash.rb, line 46
def fetch_indescriminately(name, *args)
  if @hash.has_key?(name)
    @hash[name]
  elsif @hash.has_key?(name.to_s)
    @hash[name.to_s]
  elsif @hash.has_key?(name.to_s.to_sym)
    @hash[name.to_s.to_sym]
  else
    raise ObjectHashKeyMissingError.new(name)
  end
end