Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails “什么是”呢<<-&引用;密码?_Ruby On Rails_Ruby_Railscasts - Fatal编程技术网

Ruby on rails “什么是”呢<<-&引用;密码?

Ruby on rails “什么是”呢<<-&引用;密码?,ruby-on-rails,ruby,railscasts,Ruby On Rails,Ruby,Railscasts,这段代码取自Ryan Bates在PostgreSQL中的Railscast第343集的全文搜索。我很想理解它,但是我在上找不到任何东西。它在ruby中是一个多行字符串,内容被插入,然后在PostgreSQL中执行。这是在命令行上运行脚本的标准方式。我使用它从Capistrano内部编写AWS脚本 它使用heredoc语法 它的官方名称是一个herdoc,有两种不同的使用方法。 一个是如何将其布置在起点处参见。我的答案只是链接中信息的副本/格式。我不知道它在这里被称为doc,我一直在脚本中使用

这段代码取自Ryan Bates在PostgreSQL中的Railscast第343集的全文搜索。我很想理解它,但是我在
上找不到任何东西。它在ruby中是一个多行字符串,内容被插入,然后在PostgreSQL中执行。这是在命令行上运行脚本的标准方式。我使用它从Capistrano内部编写AWS脚本

它使用heredoc语法


它的官方名称是一个
herdoc
,有两种不同的使用方法。
一个是如何将其布置在起点处
参见。我的答案只是链接中信息的副本/格式。我不知道它在这里被称为doc,我一直在脚本中使用它。感谢您解释历史:
rank = <<-RANK
  ts_rank(to_tsvector(name), plainto_tsquery(#{sanitize(query)})) +
  ts_rank(to_tsvector(content), plainto_tsquery(#{sanitize(query)}))
RANK
def sample_method
    heredoc1 = <<-NAME
        This is a sample heredoc
    NAME

    heredoc2 = <<OTHERHEREDOC
        Both of these are the same thing
OTHERHEREDOC
end