Heads up: This description was created by AI and might not be 100% accurate.

text2array.rb

This Ruby code snippet demonstrates how to capture multi-line strings into a variable. It uses the <<~ operator to create the text variable, containing three lines. Then, the lines variable is created by splitting text into an array of lines, removing trailing newlines (chomp) from each line.

Ruby code snippet

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

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

Executed with Ruby 3.4.5.