Skip to content

Selective inspect of instance variables#13555

Merged
byroot merged 1 commit into
ruby:masterfrom
byroot:instance_variables_to_inspect
Jun 9, 2025
Merged

Selective inspect of instance variables#13555
byroot merged 1 commit into
ruby:masterfrom
byroot:instance_variables_to_inspect

Conversation

@byroot

@byroot byroot commented Jun 7, 2025

Copy link
Copy Markdown
Member

[Feature #21219]

Make Kernel#inspect ask which instance variables should be dumped by the result of #instance_variables_to_inspect.

@byroot
byroot requested a review from nobu June 7, 2025 07:38
@cloudbees-smart-tests

This comment has been minimized.

Make Kernel#inspect ask which instance variables should be dumped by
the result of `#instance_variables_to_inspect`.

Co-Authored-By: Jean Boussier <[email protected]>
@byroot
byroot force-pushed the instance_variables_to_inspect branch from 6ddd72d to e643b25 Compare June 7, 2025 07:59
@byroot
byroot merged commit f4135fe into ruby:master Jun 9, 2025
@byroot
byroot deleted the instance_variables_to_inspect branch June 9, 2025 07:25

@joshuay03 joshuay03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be so useful! I had a few suggestions while reading this in passing—let me know if you agree with them, and I'd be happy to send a PR.

Comment thread NEWS.md
Comment on lines +19 to +20
* `Kernel#inspect` now check for the existence of a `#instance_variables_to_inspect` method
allowing to control which instance variables are displayed in the `#inspect` string:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `Kernel#inspect` now check for the existence of a `#instance_variables_to_inspect` method
allowing to control which instance variables are displayed in the `#inspect` string:
* `Kernel#inspect` now checks for the existence of a `#instance_variables_to_inspect` method,
allowing control over which instance variables are displayed in the `#inspect` string:

end

ruby_version_is "3.5" do
it "calls #instance_variables_to_inspect private method to know which variables to display" do

@joshuay03 joshuay03 Jun 9, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this I assumed it had to be a private method, but the implementation tells me it doesn't. What do you think about removing the mention of private here and making the method public in the empty override case (see next suggestion) so both are covered?

Suggested change
it "calls #instance_variables_to_inspect private method to know which variables to display" do
it "calls #instance_variables_to_inspect method to know which variables to display" do

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed it had to be a private method,

No method ever have to be private. e.g. method_missing is supposed to be private, but nothing will break if it isn't.

@password = "hunter2"
end
obj.singleton_class.class_eval do
private def instance_variables_to_inspect = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private def instance_variables_to_inspect = []
def instance_variables_to_inspect = []

joshuay03 added a commit to joshuay03/ruby that referenced this pull request Jun 9, 2025
joshuay03 added a commit to joshuay03/ruby that referenced this pull request Jun 9, 2025
@joshuay03 joshuay03 mentioned this pull request Jun 9, 2025
@joshuay03

Copy link
Copy Markdown
Contributor

let me know if you agree with them, and I'd be happy to send a PR

Actually it's late here so I've just opened this if you decide to merge them: #13564

joshuay03 added a commit to joshuay03/ruby that referenced this pull request Jun 10, 2025
joshuay03 added a commit to joshuay03/ruby that referenced this pull request Jun 10, 2025
byroot pushed a commit that referenced this pull request Jun 10, 2025
sms021019 pushed a commit to sms021019/ruby that referenced this pull request Jun 17, 2025
Fryguy added a commit to Fryguy/pp that referenced this pull request Aug 13, 2025
This supports the new `instance_variables_to_inspect` method from Ruby
core that was added in ruby/ruby#13555.

If `instance_variables_to_inspect` is defined, then
`pretty_print_instance_variables` will use it.

Additionally, this commit introduces tests for both
`pretty_print_instance_variables` and `instance_variables_to_inspect`.
nobu pushed a commit to nobu/ruby that referenced this pull request Oct 5, 2025
…core

This supports the new `instance_variables_to_inspect` method from Ruby
core that was added in ruby#13555.

If `instance_variables_to_inspect` is defined, then
`pretty_print_instance_variables` will use it.

Additionally, this commit introduces tests for both
`pretty_print_instance_variables` and `instance_variables_to_inspect`.

ruby/pp@9cea466c95
headius added a commit to headius/jruby that referenced this pull request Nov 18, 2025
headius added a commit to headius/jruby that referenced this pull request Nov 18, 2025
hamajyotan added a commit to hamajyotan/pp that referenced this pull request Dec 25, 2025
Ruby supports calling instance_variables_to_inspect even when
it is defined as a private method (ruby/ruby#13555).

This change aligns pp with Ruby's behavior.
hamajyotan added a commit to hamajyotan/pp that referenced this pull request Dec 26, 2025
Ruby supports calling instance_variables_to_inspect even when
it is defined as a private method (ruby/ruby#13555).

This change aligns pp with Ruby's behavior.
mame pushed a commit to ruby/pp that referenced this pull request Dec 26, 2025
* Support private instance_variables_to_inspect in pp

Ruby supports calling instance_variables_to_inspect even when
it is defined as a private method (ruby/ruby#13555).

This change aligns pp with Ruby's behavior.
matzbot pushed a commit that referenced this pull request Dec 26, 2025
(ruby/pp#70)

* Support private instance_variables_to_inspect in pp

Ruby supports calling instance_variables_to_inspect even when
it is defined as a private method (#13555).

This change aligns pp with Ruby's behavior.

ruby/pp@8450e76db6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants