ruby 中的多行字符串(multiple lines of string) %Q, %w, %q
访问量: 4028
%Q 代表一个 双引号的字符串, 例如
a = "foo"
a = %Q{ foo }
%q 代表单引号字符串, 不能使用 #{var}的形式。 例如:
b = 'bar
bar'
b = %q{bar
bar}
输出:
%q, %Q, %w 后面可以跟着: {}, [], ||
例如:
%Q[ hello ]
%Q| hello |
都是一样的。
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}
cde
def
this is a CONST: #{CONST}
%q, %Q, %w 后面可以跟着: {}, [], ||
例如:
%Q[ hello ]
%Q| hello |
都是一样的。