Sha256: 24c5b0b92f210bf6fa2e9371357d08fc3de55cd8d41aa359c88421ae736704be
Contents?: true
Size: 576 Bytes
Versions: 6
Compression:
Stored size: 576 Bytes
Contents
# Monkeypatch some convenience methods in to the String class. class String # Adds a comment string (`"# "`) after every newline in a string. # # @param indent_empty_lines [Boolean] # @return [void] def comment!(indent_empty_lines = true) re = indent_empty_lines ? /^/ : /^(?!$)/ gsub!(re, "# ") end # Returns a copy of a string with a comment (`"# "`) after every newline in a string. # # @param indent_empty_lines [Boolean] # @return [String] def comment(indent_empty_lines = true) dup.tap { |s| s.comment!(indent_empty_lines) } end end
Version data entries
6 entries across 6 versions & 2 rubygems