Class: Hash

Inherits:
Object show all
Defined in:
lib/cool_extensions/hash.rb

Instance Method Summary collapse

Instance Method Details

#largest_keyObject



3
4
5
6
7
8
9
10
# File 'lib/cool_extensions/hash.rb', line 3

def largest_key
  rows =[]
  keys.each_with_index do |f, i|
    rows << [f.to_s.length, i]
  end
  index = rows.sort_by{|x| x[0]}.last[1]
  keys[index]
end

#rowizedObject



12
13
14
15
16
17
# File 'lib/cool_extensions/hash.rb', line 12

def rowized
  max_key_length = largest_key.length
  keys.map do |key|
    "#{key.to_s.rjust(max_key_length)}: #{self[key]}\n"
  end
end