Class: Hash

Inherits:
Object show all
Defined in:
lib/smklib/hash_ext.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id) ⇒ Object



3
4
5
# File 'lib/smklib/hash_ext.rb', line 3

def method_missing(id)
    to_hash[id.id2name]
end

Instance Method Details

#find_multiple_key_values(array) ⇒ Object

takes an array of keys and returns an array of values it would really be ideal to extend the definition of []



9
10
11
12
# File 'lib/smklib/hash_ext.rb', line 9

def find_multiple_key_values(array)
  return [self[array]] unless array.is_a? Array
  array.collect { |k| self[k] }
end

#inspectObject



14
15
16
17
# File 'lib/smklib/hash_ext.rb', line 14

def inspect
	a = keys.collect { |key| n = (key.respond_to?(:to_s)) ? key.to_s : nil; [key, n] }.sort { |l, r| l[1] <=> r[1] }
	"{" + a.collect { |(key, junk)| key.inspect + "=>" + self[key].inspect }.join(", ") + "}"
end