Feature #19045
closed[Proposal] Add support Data#pretty_print
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">
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
Since pp.rb
is a part of a default gem now, you have to consider the compatibility with older versions.
Updated by osyo (manga osyo) about 2 years ago
nobu (Nobuyoshi Nakada) wrote in #note-2:
Since
pp.rb
is a part of a default gem now, you have to consider the compatibility with older versions.
Thanks.
I've tried to fix it, but what do you think.
https://github.com/ruby/ruby/pull/6521/commits/b322ba67548d0068894cc198ee073ad2ec0c7c51
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
"3.2" <= RUBY_VERSION
won't work when RUBY_VERSION
is "3.10", but probably never.
And it is needed in the test.
Can't you send the PR to ruby/pp, so it will be tested with older versions?
Updated by osyo (manga osyo) about 2 years ago
- Status changed from Open to Closed
Applied in changeset git|7b7e5153e81288fe57ae64f2e1db228435156aeb.
[ruby/pp] [Feature #19045] Add support Data#pretty_print
Updated by osyo (manga osyo) about 2 years ago
nobu (Nobuyoshi Nakada) wrote in #note-4:
"3.2" <= RUBY_VERSION
won't work whenRUBY_VERSION
is "3.10", but probably never.
And it is needed in the test.
Can't you send the PR to ruby/pp, so it will be tested with older versions?
Sorry for the delay in replying.
Thank you.