Selective inspect of instance variables#13555
Conversation
This comment has been minimized.
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]>
6ddd72d to
e643b25
Compare
joshuay03
left a comment
There was a problem hiding this comment.
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.
| * `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: |
There was a problem hiding this comment.
| * `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 |
There was a problem hiding this comment.
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?
| 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 |
There was a problem hiding this comment.
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 = [] |
There was a problem hiding this comment.
| private def instance_variables_to_inspect = [] | |
| def instance_variables_to_inspect = [] |
Actually it's late here so I've just opened this if you decide to merge them: #13564 |
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`.
…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
For Ruby 4.0 compatibility. See ruby/ruby#13555 See jruby#9061
For Ruby 4.0 compatibility. See ruby/ruby#13555 See jruby#9061
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.
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.
* 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.
(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
[Feature #21219]
Make Kernel#inspect ask which instance variables should be dumped by the result of
#instance_variables_to_inspect.