[ruby/pp] Extract pp_hash_pair

The method which prints single pair of a hash, to make extending
pretty printing Hash easier, apart from Hash construct itself.

https://github.com/ruby/pp/commit/3fcf2d1142
This commit is contained in:
Nobuyoshi Nakada 2021-09-05 22:19:48 +09:00 committed by git
parent 37b8fc7477
commit 6e704311bb
2 changed files with 22 additions and 24 deletions

View File

@ -286,16 +286,21 @@ class PP < PrettyPrint
group(1, '{', '}') {
seplist(obj, nil, :each_pair) {|k, v|
group {
pp k
text '=>'
group(1) {
breakable ''
pp v
}
pp_hash_pair k, v
}
}
}
end
# A pretty print for a pair of Hash
def pp_hash_pair(k, v)
pp k
text '=>'
group(1) {
breakable ''
pp v
}
end
end
include PPMethods

View File

@ -247,25 +247,18 @@ end
class PPInheritedTest < Test::Unit::TestCase
class PPSymbolHash < PP
def pp_hash(obj)
group(1, "{", "}") {
seplist(obj, nil, :each_pair) {|k, v|
case k
when Symbol
text k.inspect.delete_prefix(":")
text ":"
sep = " "
else
pp k
text "=>"
sep = ""
end
group(1) {
breakable sep
pp v
}
def pp_hash_pair(k, v)
case k
when Symbol
text k.inspect.delete_prefix(":")
text ":"
group(1) {
breakable
pp v
}
}
else
super
end
end
end