Code example:
create_data_with(
first: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
second: <<~TEXT
Aenean vel ex bibendum, egestas tortor sit amet, tempus lorem. Ut sit
amet rhoncus eros. Vestibulum ante ipsum primis in faucibus orci
luctus et ultrices posuere cubilia curae; Quisque non risus vel lacus
tristique laoreet. Curabitur quis auctor mauris, nec tempus mauris.
TEXT,
third: "Nunc aliquet ipsum at semper sodales."
)
The error is present in this line:
second: <<~TEXT
RuboCop describes it like this:
Lint/Syntax: unterminated string meets end of file
(Using Ruby 3.1 parser; configure using TargetRubyVersion parameter, under AllCops)
second: <<~TEXT
Can you please tell me what should be the syntax? I need to keep the look and use of <<~.
With heredocs, the parser expects the exact delimiter to close the literal. You open with
TEXT, but you close withTEXT,and ruby doesn't consider this literal closed. However, you can (and should in this case) put the comma after the opening delimiter. Here's a fix:You can even call methods this way. For example, the squiggly heredoc (
<<~TEXT) was previously done in rails as<<-TEXT.strip_heredoc