Text2array.rb
This content was produced by an LLM and could include errors.
このスクリプトはヒアドキュメント(<<~TEXT)で複数行テキストを作成し、.lines で行ごとの配列 ["a\n", "b\n", "c\n"] に分解した後、map(&:chomp) で末尾の改行を取り除いた ["a", "b", "c"] を得ます。テキストを行単位で処理する際の定石です。
text = <<~TEXT
a
b
c
TEXT
#=> "a\nb\nc\n"
lines = text.lines.map(&:chomp)
#=> ["a", "b", "c"]
Ruby 4.0.6