“<<-"是什么意思?在 Ruby 中是什么意思? [英] What does &quot;&lt;&lt;-&quot; mean in Ruby?

查看:104
本文介绍了“<<-"是什么意思?在 Ruby 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

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

这段代码有什么作用?<<- 叫什么?

What does this code do? What is <<- called?

推荐答案

它叫做 heredoc.一种定义多行字符串的简单方法,其中可能包含单引号或双引号,而无需对其进行转义.

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

查看更多此处,例如.

您经常使用heredoc 来定义大块代码.一些编辑器知道这一点,并且可以在那里为您突出显示语法(如果您指定语言).看:

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:

这篇关于“<<-"是什么意思?在 Ruby 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆