Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def pretty_print_cycle(q)
# This method should return an array of names of instance variables as symbols or strings as:
# +[:@a, :@b]+.
def pretty_print_instance_variables
ivars = respond_to?(:instance_variables_to_inspect) ? instance_variables_to_inspect : instance_variables
ivars = respond_to?(:instance_variables_to_inspect, true) ? instance_variables_to_inspect || instance_variables : instance_variables
ivars.sort
end

Expand Down
4 changes: 3 additions & 1 deletion test/test_pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def a.pretty_print_instance_variables() [:@b] end

def test_iv_hiding_via_ruby
a = Object.new
def a.instance_variables_to_inspect() [:@b] end
a.singleton_class.class_eval do
private def instance_variables_to_inspect() [:@b] end
end
a.instance_eval { @a = "aaa"; @b = "bbb" }
assert_match(/\A#<Object:0x[\da-f]+ @b="bbb">\n\z/, PP.pp(a, ''.dup))
end
Expand Down