長すぎるので複数の行に1つの文字列を書こうとしていましたが、私はthis solutionに到着しました。私は多くの方法を見ましたが、彼らはこの場合のパフォーマンスには連結または補間とall I could find was this.を使用するかどうか、これが行うことができると私は思っていたRuby documentationこれらの6つのRuby文字列構文の違いは、連結、補間なのか何か他のもの
my_original = 'what I originally had ' +
'across multiple lines'
# executes to: "what I originally had across multiple lines"
new_style = 'new format to '\
'span multiple lines'
# executes to: "new format to span multiple lines\n"
でそれについて何かを見つけることができなかったことは、この中には特に重要ではありませんケースの中で何が起こっているのかを知ることは、傷つきません。そこで、これらの違いを疑問に思っていました。
my_original = 'what I originally had ' +
'across multiple lines'
# executes to: "what I originally had across multiple lines"
s_one = 'I assume this is a more '
s_two = 'verbose version of the '
s_three = 'first example.'
my_string = s_one + s_two + s_three
# executes to: "I assume this is a more verbose version of the first example."
my_first_solution = 'that breaks whenever'
my_first_solution << 'ruby 3.0 might be released'
# executes to:
style_i_used = 'which can span multiple '\
'lines without having '\
'extra white space'
# executes to: "which can span multiple lines without having extra white space"
another_string = <<-HEREDOC
when you don't mind
really wonky indentation
or having extra spaces.
HEREDOC
# executes to:"when you don't mind \nreally wonky indentation \n or having extra spaces\n and new lines. \n"
# "Is this just a one line string with no special characters?# executes to:
another_string = <<~HEREDOC
I assume this is the same as
the non squiggly version with
stripping between lines.
HEREDOC
# executes to: "I assume this is the same as \nthe non squiggly version with \nstripping between lines.\n"
#Edit
another_one =
"I did not originally include; however,
this one also adds a bunch of extra
white space and new lines."
# executes to:"I did not originally include; however,\n this one also adds a bunch of extra \n white space and new lines."