From 6e067fe20f5f29a3a87b1c8a2e72ff89722e15a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Tom=C3=A1s?= Date: Sat, 5 Nov 2011 13:05:38 -0400 Subject: [PATCH] hash keys colored according to class --- lib/ap/awesome_print.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ap/awesome_print.rb b/lib/ap/awesome_print.rb index 1fa98319..32fe11f5 100755 --- a/lib/ap/awesome_print.rb +++ b/lib/ap/awesome_print.rb @@ -83,18 +83,18 @@ def awesome_hash(h) keys = @options[:sorted_hash_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys data = keys.map do |key| plain_single_line do - [ awesome(key), h[key] ] + [ awesome(key), h[key], key ] end end width = data.map { |key, | key.size }.max || 0 width += @indentation if @options[:indent] > 0 - data = data.map do |key, value| + data = data.map do |key, value, hkey| if @options[:multiline] - formatted_key = (@options[:indent] >= 0 ? key.rjust(width) : indent + key.ljust(width)) + formatted_key = (@options[:indent] >= 0 ? key.rjust(width).sub!(/#{key}/, awesome(hkey)) : indent + key.ljust(width)).sub!(/#{key}/, awesome(hkey)) else - formatted_key = key + formatted_key = awesome(hkey) end indented do formatted_key << colorize(" => ", :hash) << awesome(value)