Ruby supports two comment styles: inline # comments and block =begin/=end comments. The block syntax requires markers to start at column 1 with no indentation, making it unusable inside methods, classes, or conditionals. The community-standard approach is to use multiple # lines instead, which works anywhere, supports editor shortcuts, and integrates well with RDoc/YARD. The =begin/=end syntax is still occasionally useful for file-level documentation, copyright notices, and disabling top-level code sections. Best practices for 2025+ favor # for nearly everything, with =begin reserved for niche cases like file-level RDoc markup.

5m read timeFrom railscarma.com
Post cover image
Table of contents
1. Ruby’s Two Comment Types: Inline vs Block2. The =begin / =end Block Comment Syntax3. The Practical Multiline Comment: Multiple # Lines4. Comparing the Two Approaches Side-by-Side5. Special Use Cases Where =begin / =end Still Appears6. Common Pitfalls and Mistakes7. Best Practices for Commenting in Ruby (2025–2026 Style)8. Quick Reference: All Ruby Comment Styles in One PlaceConclusion

Sort: