在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
%Q用于替代双引号的字符串. 当你需要在字符串里放入很多引号时候, 可以直接用下面方法而不需要在引号前逐个添加反斜杠 (\") >> %Q(Joe said: "Frank said: "#{what_frank_said}"") => "Joe said: "Frank said: "Hello!"""
>> %Q!Joe said: "Frank said: "#{what_frank_said}""! >> %Q[Joe said: "Frank said: "#{what_frank_said}""] >> %Q+Joe said: "Frank said: "#{what_frank_said}""+ 除此之外还可省略 >> %/Joe said: "Frank said: "#{what_frank_said}""/ => "Joe said: "Frank said: "Hello!""" %q与 >> %q(Joe said: 'Frank said: '#{what_frank_said} ' ') => "Joe said: 'Frank said: '\#{what_frank_said} ' '" %W语法近似于 >> %W(#{foo} Bar Bar\ with\ space) => ["Foo", "Bar", "Bar with space"] %w用于表示其中元素被单引号括起的数组. 比较奇怪的是 >> %w(a b c\ d \#e #{1}f) => ["a", "b", "c d", "\\#e", "\#{1}f"] %x使用`方法执行一段shell脚本并返回标准输出内容. >> %x(echo foo:#{foo}) => "foo:Foo\n" %r语法近似于 >> %r(/home/#{foo}) => "/\\/home\\/Foo/" %s用于表示symbol, 但是不会对其中表达式等内容进行转化 >> %s(foo) => :foo >> %s(foo bar) => :"foo bar" >> %s(#{foo} bar) => :"\#{foo} bar" %iRuby 2.0 之后引入的语法, 用于生成一个symbol数组 2.0.0p247 :014 > %i(a b c) => [:a, :b, :c] |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论