Home Ruby中的多行字符串(multiplelinesofstring)%q,%w,%q
Post
Cancel

Ruby中的多行字符串(multiplelinesofstring)%q,%w,%q

%Q 代表一个 双引号的字符串, 例如
a = "foo"
a = %Q{ foo }

%q 代表单引号字符串, 不能使用 #{var}的形式。 例如:
b = 'bar
bar'
b = %q{bar
bar}

  
 CONST = "apple"
 abc = %q[ abc abc
 cde
 def
 this is a CONST: #{CONST}   
 ]
 puts abc

输出:
引用
abc abc
cde
def
this is a CONST: #{CONST}


%q, %Q, %w 后面可以跟着:  {}, [], ||
例如:
%Q[ hello ]
%Q| hello |
都是一样的。
This post is licensed under CC BY 4.0 by the author.