What does “<<-” mean in Ruby?

前端 未结 4 1293
日久生厌
日久生厌 2020-12-01 15:41

For example:

code = <<-EOH
    bundle install
    bundle exec unicorn -c /etc/unicorn.cfg -D
EOH

What does this code do? What is

4条回答
  •  無奈伤痛
    2020-12-01 16:09

    It's called heredoc. An easy way to define multiline strings which may include single or double quotes without needing to escape them.

    See more here, for example.

    Often you use heredocs to define large chunks of code. Some editors know about this and can highlight syntax for you there (if you specify language). Look:

    strings vs heredocs

提交回复
热议问题