class Gumdrop::Util::HashObject

Public Class Methods

from(hash={}, recurse=true) click to toggle source
# File lib/gumdrop/util/hash_object.rb, line 65
def self.from(hash={}, recurse=true)
  h= new
  if recurse
    hash.each do |key, value|
      if value.is_a? Hash
        hash[key]= HashObject.from value
      end
    end
  end
  h.merge!(hash)
  h
end

Public Instance Methods

[](key) click to toggle source

All keys are symbols, internally

Calls superclass method
# File lib/gumdrop/util/hash_object.rb, line 6
def [](key)
  super(key.to_sym)
end
[]=(key, value) click to toggle source
Calls superclass method
# File lib/gumdrop/util/hash_object.rb, line 9
def []=(key, value)
  if value.is_a? Hash
    value= HashObject.from value, true
  end
  super(key.to_sym, value)
end
get(key) click to toggle source
# File lib/gumdrop/util/hash_object.rb, line 28
def get(key)
  self[key]
end
has_key?(key) click to toggle source
Calls superclass method
# File lib/gumdrop/util/hash_object.rb, line 41
def has_key?(key)
  super key.to_sym
end
merge(other_hash=nil, &block) click to toggle source
Calls superclass method
# File lib/gumdrop/util/hash_object.rb, line 49
def merge(other_hash=nil, &block)
  unless other_hash.nil?
    super(other_hash.to_symbolized_hash, &block)
  else
    super(other_hash, &block)
  end
end
merge!(other_hash=nil, &block) click to toggle source
Calls superclass method
# File lib/gumdrop/util/hash_object.rb, line 57
def merge!(other_hash=nil, &block)
  unless other_hash.nil?
    super(other_hash.to_symbolized_hash, &block)
  else
    super(other_hash, &block)
  end
end
method_missing(sym, *args, &block) click to toggle source
# File lib/gumdrop/util/hash_object.rb, line 16
def method_missing(sym, *args, &block)
  if self.has_key? sym.to_s or self.has_key? sym
    self[sym]
  elsif sym.to_s.ends_with? '='
    key= sym.to_s.chop
    self[key]= args[0]
  else
    # super sym, *args, &block # ???
    nil
  end
end
set(key,value=nil) click to toggle source
# File lib/gumdrop/util/hash_object.rb, line 31
def set(key,value=nil)
  if key.is_a? Hash
    key.each do |k,v|
      self[k]= v
    end
  else
    self[key]= value
  end
end
store(key,value) click to toggle source
Calls superclass method
# File lib/gumdrop/util/hash_object.rb, line 45
def store(key,value)
  super(key.to_sym, value)
end