%Q
This is an alternative for double-quoted strings, when you have more quote characters in a string.Instead of putting backslashes in front of them, you can easily write:
>> %Q(Joe said: "Frank said: "#{what_frank_said}"")
=> "Joe said: "Frank said: "Hello!"""
The parenthesis “(…)” can be replaced with any other non-alphanumeric characters and non-printing characters (pairs), so the following commands are equivalent:
>> %Q!Joe said: "Frank said: "#{what_frank_said}""!
>> %Q[Joe said: "Frank said: "#{what_frank_said}""]
>> %Q+Joe said: "Frank said: "#{what_frank_said}""+
You can use also:
>> %/Joe said: "Frank said: "#{what_frank_said}""/
=> "Joe said: "Frank said: "Hello!"""
%q
Used for single-quoted strings.The syntax is similar to %Q, but single-quoted strings are not subject to expression substitution or escape sequences.
>> %q(Joe said: 'Frank said: '#{what_frank_said} ' ')
=> "Joe said: 'Frank said: '\#{what_frank_said} ' '"
%W
Used for double-quoted array elements.The syntax is similar to %Q
>> %W(#{foo} Bar Bar\ with\ space)
=> ["Foo", "Bar", "Bar with space"]
%w
Used for single-quoted array elements.The syntax is similar to %Q, but single-quoted elements are not subject to expression substitution or escape sequences.
>> %w(#{foo} Bar Bar\ with\ space)
=> ["\#{foo}", "Bar", "Bar with space"]
%x
Uses the ` method and returns the standard output of running the command in a subshell.The syntax is similar to %Q.
>> %x(echo foo:#{foo})
=> "foo:Foo\n"
%r
Used for regular expressions.The syntax is similar to %Q.
>> %r(/home/#{foo})
=> "/\\/home\\/Foo/"
%s
Used for symbols.It’s not subject to expression substitution or escape sequences.
>> %s(foo)
=> :foo
>> %s(foo bar)
=> :"foo bar"
>> %s(#{foo} bar)
=> :"\#{foo} bar"
Thanks, Ivan
分享到:
相关推荐
Ruby,一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言,在20世纪90年代由日本人松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、...
ruby-1.9.2-p290.tar.gz,ruby,redmin,安装,
ruby-irb-1.8.7.352-13.el6.x86_64.rpm ruby-irb-1.8.7.352-13.el6.x86_64.rpm
官网原版安装包,官网的下载真的很慢...
ruby-debug-ide-0.3.1.gem
跟其它界面开发包不同的是,Ruby-GNOME2不仅仅提 供界面控件,它提供了整个GNOME 2.0的环境,包含Ruby/GLib2、Ruby/ATK、Ruby/Pango、Ruby/GTK2、Ruby/GnomeCanvas2、Ruby /GNOME2、Ruby/GnomeVFS、Ruby/GtkHtml2、...
mingw32-ruby-1.9.1-wxruby-2.0.1-setup.exe
ruby-debug-base19-0.11.26.gem
瑞传 RUBY-9719VG2AR主板pdf,瑞传 RUBY-9719VG2AR主板
ruby-2.6.5.tar.gz 来自官网, ruby-2.6.5.tar.gz 来自官网, ruby-2.6.5.tar.gz 来自官网,
ruby-1.9.2-preview1-x64-mswin64_80
ruby-oci8-2.1.5-x86-mingw32.gem,ruby连接oracle数据库gem包
ruby-2.4.1.tar.gz
sqlite3-ruby-mswin32.gem
MySQL分析 innodb
ruby-build 是一个 rbenv 插件,它提供了一个 rbenv install 命令来在类 UNIX 系统上编译和安装不同版本的 Ruby。你还可以在需要精确控制 Ruby 版本安装的环境中使用不带 rbenv 的 ruby-build。用法在开始之前,...
ruby-1.8.5.tar for Liunx 开魔力宝贝单机必须软件之一
ruby-1.9.3-p547.tar.gz
ruby-libs-1.8.7.352-13.el6.x86_64.rpm ruby-libs-1.8.7.352-13.el6.x86_64.rpm
ruby-2.4.5 由于官方下载速度慢,所以在这里提供下载。