Text2array.rb

This content was produced by an LLM and could include errors.

This script stores multiline text, then uses .lines.map(&:chomp) to efficiently convert the string into a clean array of individual strings, removing trailing newlines.

text = <<~TEXT
a
b
c
TEXT
#=> "a\nb\nc\n"

lines = text.lines.map(&:chomp)
#=> ["a", "b", "c"]

Ruby 4.0.3