[ruby/pp] Get rid of hardcoded class name
So that the `pp` method can work in inherited classes with that class. https://github.com/ruby/pp/commit/f204df3aad
This commit is contained in:
parent
82a4c3af16
commit
37b8fc7477
@ -93,7 +93,7 @@ class PP < PrettyPrint
|
|||||||
#
|
#
|
||||||
# PP.pp returns +out+.
|
# PP.pp returns +out+.
|
||||||
def PP.pp(obj, out=$>, width=width_for(out))
|
def PP.pp(obj, out=$>, width=width_for(out))
|
||||||
q = PP.new(out, width)
|
q = new(out, width)
|
||||||
q.guard_inspect_key {q.pp obj}
|
q.guard_inspect_key {q.pp obj}
|
||||||
q.flush
|
q.flush
|
||||||
#$pp = q
|
#$pp = q
|
||||||
|
@ -245,4 +245,36 @@ if defined?(RubyVM)
|
|||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_hash_override
|
||||||
|
obj = {k: 1, "": :null, "0": :zero, 100 => :ten}
|
||||||
|
assert_equal <<~EXPECT, PPSymbolHash.pp(obj, "".dup)
|
||||||
|
{k: 1, "": :null, "0": :zero, 100=>:ten}
|
||||||
|
EXPECT
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user