Project

General

Profile

Actions

Feature #19045

closed

[Proposal] Add support Data#pretty_print

Added by osyo (manga osyo) about 2 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:110241]

Description

While trying out the Data library I noticed that Data#pretty_print is not supported.
Data#inspect included members, but Data#pretty_print does not.

require "pp"

D = Data.define(:hoge, :foo, :bar)
data = D.new("hoge", "foo", "bar")

# Members is included
puts data.inspect
# => #<data D hoge="hoge", foo="foo", bar="bar">

# Members is not included
puts PP.pp(data, "")
# => #<data D:...>

Since Struct#pretty_print is supported, why not support Data#pretty_print as well.

require "pp"

S = Struct.new(:hoge, :foo, :bar)
str = S.new("hoge", "foo", "bar")

# Supported Struct#pretty_print
puts PP.pp(str, "", 20)
# => #<struct S
#     hoge="hoge",
#     foo="foo",
#     bar="bar">

PR: https://github.com/ruby/ruby/pull/6521
Sample:

D = Data.define(:hoge, :foo, :bar)
data = D.new("hoge", "foo", "bar")

puts PP.pp(data, "", 20)
# => #<data D
#     hoge="hoge",
#     foo="foo",
#     bar="bar">
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0