class Hashish

Hash-ish!

This class is implemented using composition rather than inheritance so that we have control over what operations it exposes to peers.

Public Class Methods

new(hash={}) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 10
def initialize(hash={})
  @hash = hash.dup
  stringify_keys
  hashishify_values
end

Public Instance Methods

==(other_obj) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 16
def ==(other_obj)
  other_obj.class == self.class &&
  other_obj.hash == self.hash
end
[](key) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 21
def [](key)
  @hash[normalize(key)]
end
[]=(key, value) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 25
def []=(key, value)
  @hash[normalize(key)] = value
end
dup() click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 29
def dup
  Hashish.new(JSON.parse(@hash.to_json))
end
each(&block) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 33
def each(&block)
  @hash.each(&block)
end
empty?() click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 37
def empty?
  @hash.empty?
end
has_key?(name) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 41
def has_key?(name)
  @hash.has_key? normalize(name)
end
hash() click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 45
def hash
  @hash
end
keys() click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 49
def keys
  @hash.keys
end
length() click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 53
def length
  @hash.length
end
merge(other_hash) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 57
def merge(other_hash)
  Hashish.new(@hash.merge(other_hash))
end
merge!(other_hash) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 61
def merge!(other_hash)
  @hash.merge! other_hash
  self
end
to_json(obj) click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 66
def to_json(obj)
  @hash.to_json(obj)
end
to_s() click to toggle source
# File lib/aviator/core/utils/hashish.rb, line 70
def to_s
  str = "{"
  @hash.each do |key, value|
    if value.kind_of? String
      value = "'#{value}'"
    elsif value.nil?
      value = "nil"
    elsif value.kind_of? Array
      value = "[#{value.join(", ")}]"
    end

    str += " #{key}: #{value},"
  end

  str = str[0...-1] + " }"
  str
end