不含插值的 Heredoc
October 14, 2020
有時你會想使用 Ruby 的 Heredoc 但不進行插值('#{....}')。只要在你的關鍵字前後加上單引號就可以做到:
doc = <<-'SONG'
Business men, they drink my wine
#{person} dig my earth
None will level on the line
Nobody offered his word
Hey, hey
SONG
有時你會想使用 Ruby 的 Heredoc 但不進行插值('#{....}')。只要在你的關鍵字前後加上單引號就可以做到:
doc = <<-'SONG'
Business men, they drink my wine
#{person} dig my earth
None will level on the line
Nobody offered his word
Hey, hey
SONG