Skip to content

Fix width_for for zero winsize and object_group for anonymous classes - #103

Open
afurm wants to merge 1 commit into
ruby:masterfrom
afurm:fix/width-for-zero-and-anonymous-object-group
Open

afurm wants to merge 1 commit into
ruby:masterfrom
afurm:fix/width-for-zero-and-anonymous-object-group

Conversation

@afurm

@afurm afurm commented Oct 15, 2026

Copy link
Copy Markdown
Member

What

PP.width_for treated a zero winsize width as usable because 0 is truthy in Ruby, so it returned -1 instead of falling back to COLUMNS / 80. Non-tty or constrained devices can report width 0; treat that like a missing width.

PP#object_group also concatenated obj.class.name, which is nil for anonymous classes and raised TypeError. Use class.to_s when name is nil so custom pretty_print implementations can group anonymous class instances.

Tests

  • test_width_for_zero_winsize — winsize [24, 0] yields 79
  • test_object_group_anonymous_class — object_group on Class.new.new no longer raises

ruby -Ilib:test test/test_pp.rb -n '/width_for_zero|object_group_anonymous|list0123/' → 4 tests, 0 failures.

winsize can report width 0; treating that as truthy made width_for return
-1. Fall back to COLUMNS / 80 when width is zero. Also use class.to_s when
class.name is nil so object_group works for anonymous classes.

This branch has not been deployed

No deployments
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.

1 participant