gpt4 book ai didi

ruby - 什么是 <-- Ruby 字符串?以及如何在其中插入变量?

转载 作者:数据小太阳 更新时间:2023-10-29 07:44:27 24 4
gpt4 key购买 nike

<--网上好像查不到,只好来这里提问了。

它们的可搜索名称是什么,我如何添加内联变量?

最佳答案

该语法用于声明 HERE DOCUMENT http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#here_doc

There's a line-oriented form of the string literals that is usually called as `here document'. Following a << you can specify a string or an identifier to terminate the string literal, and all lines following the current line up to the terminator are the value of the string. If the terminator is quoted, the type of quotes determines the type of the line-oriented string literal. Notice there must be no space between << and the terminator.

If the - placed before the delimiter, then all leading whitespcae characters (tabs or spaces) are stripped from input lines and the line containing delimiter. This allows here-documents within scripts to be indented in a natural fashion.

关于插值,链接提供了更多详细信息,但如果您的字符串如下定界(忽略此页面的颜色格式),它就像一个双引号字符串

<<-HERE
I can interpolate #{foo}
HERE

而它就像一个单引号字符串

<<-'HERE'
This will print out #{foo} as text
HERE

原始镐也是一个很好的来源 http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html

关于ruby - 什么是 <-- Ruby 字符串?以及如何在其中插入变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6951446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com