Skip to content

Add guideline discouraging embedded newlines in puts#977

Closed
andyw8 wants to merge 1 commit into
rubocop:masterfrom
andyw8:discourage-embedded-newlines-in-puts
Closed

Add guideline discouraging embedded newlines in puts#977
andyw8 wants to merge 1 commit into
rubocop:masterfrom
andyw8:discourage-embedded-newlines-in-puts

Conversation

@andyw8

@andyw8 andyw8 commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Note: PR co-authored with Claude Code

Summary

This PR adds a guideline discouraging the use of embedded newline characters (\n) in puts calls, in favor of using separate puts calls.

Motivation

I've noticed that AI models frequently generate Ruby code using the pattern puts "\nmessage" when adding blank lines to output. I suspect this is due to training bias from Python codebases, where print("\nmessage") is an accepted and common style.

However, in Ruby, the idiomatic approach is to use separate puts calls:

puts
puts 'message'

This is more readable and aligns better with Ruby conventions.

Next Steps

I was intending to add a new RuboCop cop to enforce this guideline, but I wanted to open this PR here first for discussion. If the community agrees this is a worthwhile guideline, I'll proceed with implementing the corresponding cop in RuboCop.

Changes

  • Added a new section "Separate puts for Newlines" in the Misc section
  • Provided clear examples of the discouraged and preferred patterns

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@koic

koic commented Jun 26, 2026

Copy link
Copy Markdown
Member

This is more readable and aligns better with Ruby conventions.

I'm not sure how common this convention actually is. I've seen "\nmessage" used intentionally to reduce I/O overhead. It might be worth considering whether this should be enforced as a universal style rule.

@andyw8 andyw8 closed this Jun 27, 2026
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.

2 participants