Skip to content

Instantly share code, notes, and snippets.

@hiroshiro
Created March 4, 2014 22:11
Show Gist options
  • Save hiroshiro/5c217fe548b3508e600d to your computer and use it in GitHub Desktop.
Save hiroshiro/5c217fe548b3508e600d to your computer and use it in GitHub Desktop.
複数行の文字列を格納する。Rubyのコード"def test\n some_method\n other_method\nend\n"
code = <<-END.gsub(/^\s+\|/, '')
|def test
| some_method
| other_method
|end
END
@hiroshiro
Copy link
Author

複数行のヒアドキュメントを用いるときは、 先頭のスペースも保持してしまうということを頭に入れておかなければなりません。 過剰なスペースを取り除くためのマージンを採用するのを実用的です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment