创建数组(%w)
%w(one two tree four five) => ["one", "two", "three", "four", "five"] # 数组元素都是String类型
创建字符串(%Q,%q)
name = "Marlon" %Q(My name is #{name}) # %Q生成的字符串是用双引号包含的,里面可以识别#{} => "My name is Marlon" %q(My name is #{name}) # %q生成的字符串是用但引号包含的,不可识别#{} => 'My name is #{name}'
创建正则表达式
%r(Come on!)
=> /Come on!/
共同点
# 创建对象时不一定要用括号,可以用其他的进行配对,如:
1 %w!one two three! 2 => ["one", "two", "three"] 3 %Q?Come on!? 4 => "Come on!" 5 %q@Come on!@ 6 => "Come on!" 7 %r&Come on!& 8 => /Come on!/