What does “<<-” mean in Ruby?

前端 未结 4 1294
日久生厌
日久生厌 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:33

    There is also a newer HEREDOC syntax for Ruby <<~END that more closely resembles what you would typically see in most shells and other languages with the ~ instead of the - to tell Ruby to strip the leading whitespace to match the least indented line in the block.

    https://infinum.co/the-capsized-eight/multiline-strings-ruby-2-3-0-the-squiggly-heredoc

提交回复
热议问题