class Hash

Public Instance Methods

flat_each(prefix=[]) { |prefix| ... } click to toggle source
# File lib/dgaff/hash.rb, line 17
def flat_each(prefix=[], &blk)
  each do |k,v|
    if v.is_a?(Hash)
      v.flat_each(prefix+[k], &blk)
    else
      yield prefix+[k], v
    end
  end
end
flatify() click to toggle source
# File lib/dgaff/hash.rb, line 27
def flatify
  hh = {}
  self.to_enum(:flat_each).collect { |k,v| [k.join("-"),v] }.collect {|attrib| hh[attrib[0]] = attrib[1]}
  return hh
end
get(key) click to toggle source
# File lib/dgaff/hash.rb, line 2
def get(key)
  self[key.to_s]||self[key.to_sym]
end
highest() click to toggle source
# File lib/dgaff/hash.rb, line 33
def highest
  high_pair = self.max {|a,b| a[1] <=> b[1]}
  return {high_pair[0] => high_pair[1]}
end
lowest() click to toggle source
# File lib/dgaff/hash.rb, line 38
def lowest
  low_pair = self.min {|a,b| a[1] <=> b[1]}
  return {low_pair[0] => low_pair[1]}
end
set(key, value) click to toggle source
# File lib/dgaff/hash.rb, line 6
def set(key, value)
  if self[key.to_s]
    self[key.to_s] = value
  elsif self[key.to_sym]
    self[key.to_sym] = value
  else
    self[key.to_sym] = value
  end
  self
end