diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-07 06:39:56 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-07 06:39:56 +0000 |
commit | de19e0159964553bfc981f75c61891a47239e45a (patch) | |
tree | 97a0cd2e6aaaf732cba1f3ccad0a1395ff67b6f5 /lib | |
parent | 0378ed5bad591054634a50c4118f27b4c2e0ce6d (diff) | |
download | ruby-de19e0159964553bfc981f75c61891a47239e45a.tar.gz ruby-de19e0159964553bfc981f75c61891a47239e45a.tar.xz ruby-de19e0159964553bfc981f75c61891a47239e45a.zip |
* lib/pp.rb (PP::PPMethods#pp_hash): sort if
all keys are strings, symbols or integers.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pp.rb | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -247,7 +247,14 @@ class PP < PrettyPrint def pp_hash(obj) group(1, '{', '}') { - seplist(obj, nil, :each_pair) {|k, v| + keys = obj.keys + if keys.all? {|k| k.respond_to? :to_str } || + keys.all? {|k| k.is_a? Symbol } || + keys.all? {|k| k.is_a? Integer } + keys.sort! + end + seplist(keys, nil, :each) {|k| + v = obj[k] group { pp k text '=>' |