Skip to content

Add String#paragraphs and String#sentences - #351

Merged
trans merged 2 commits into
mainfrom
feature/sentences-paragraphs
Nov 25, 2026
Merged

trans merged 2 commits into
mainfrom
feature/sentences-paragraphs

Conversation

@trans

@trans trans commented Nov 25, 2026

Copy link
Copy Markdown
Member

Two string methods salvaged from the retired Language gem, rewritten, with an each_ form of each.

String#paragraphs

Splits a string at its blank lines.

"One.\nStill one.\n\nTwo.".paragraphs  #=> ["One.\nStill one.", "Two."]
  • Any number of blank lines is one separator, and a line holding only whitespace counts as blank.
  • The lines inside a paragraph are left as they are.
  • Blank lines at the start and end are ignored. \r\n line endings work.

String#sentences

Splits a string into sentences by their closing punctuation.

"It works. Does it? Yes!".sentences     #=> ["It works.", "Does it?", "Yes!"]
"Pi is 3.14. See pi.rb.".sentences      #=> ["Pi is 3.14.", "See pi.rb."]
'He said "Stop." Then he left.'.sentences  #=> ["He said \"Stop.\"", "Then he left."]
  • A sentence ends at ., ?, ! or …, plus any closing quotation marks or brackets, when followed by whitespace or the end of the text.
  • A blank line ends a sentence too, so a heading stands on its own.
  • The full-width marks 。!? end a sentence without a following space.
  • It goes by punctuation alone, so an abbreviation is taken for a sentence end: "Dr. Who is in.".sentences is ["Dr.", "Who is in."]. This is documented on the method and has a test.

Also

  • String#each_paragraph and String#each_sentence, each in its own file. Without a block they return an enumerator.
  • All four load with require 'facets'.
  • Lemon tests (23) and a QED demo for each method; HISTORY entry under Unreleased.
  • A second commit adds a note to work/TODO.md: go through ProUtils next for things that belong in Facets.

Neither name is defined by Ruby or ActiveSupport.

🤖 Generated with Claude Code

trans and others added 2 commits November 24, 2026 23:23
From the Language gem, rewritten.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit d5f1bca into main Nov 25, 2026
16 checks passed
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