Ruby%Q,%Q,%W,%W,%x,%r,%s,%i

Source: Internet
Author: User

%Q

The string used to replace the double quotation marks. When you need to put a lot of quotes in the string, you can use the following method without adding a backslash (\ ") to the quotation marks.

%Q (Joe said: "Frank said:"#{what_frank_said}"")"Joe said:""hello!" "     " 

(...) Other non-alphanumeric symbols or paired symbols can also be substituted, such as ..., ..., ..., ... [ ] ! ! + + { } , < > ...,........ such as.

The following wording is all equivalent to the above:

%q! Joe said: "Frank said:"#{what_frank_said} ""!  %q[joe said: "Frank said:"#{what_frank_said}""%q+joe said: "Frank said:"#{What_ Frank_said}"" +             

In addition, writing can be omitted Q :

%/joe said: "Frank said:" #{what_frank_said} ""/"Joe said:"  
%q

%Qsimilar, but represents a single-quote string

%q (Joe said: ' Frank said: ' #{what_frank_said} ')"Joe said: ' Frank said: '\#   
%W

The syntax is approximate to the %Q array in which the elements are enclosed in double quotation marks.

%W (#{foo} bar withspace)["foo" "Bar" "Bar withspace"  
%w

Used to represent an array where the elements are enclosed in quotation marks. It is strange that \ (slash spaces) will be converted to (spaces), but the rest of the content will not.

\#e #{1}f)["a""B""C D""\ \#e""\#{1}f"]   
%x

Use the ' method to execute a shell script and return the standard output content.

%x (echo foo:#{foo})"Foo:foo\  n     
%r

Syntax is approximate %Q and is used for regular expressions.

%r (/home/#{foo}"/\ \ home\ \        
%s

Used to represent the symbol, but it does not convert content such as an expression

%s (foo): Foo%s (foo bar): "foo bar"%s (#{foo} bar): "\#{foo} bar"   
%i

Syntax introduced after Ruby 2.0, used to generate a symbol array

2.  0.  0:%i (a b c)[: a: b: C           

Original address: https://ruby-china.org/topics/18512

Ruby%Q,%Q,%W,%W,%x,%r,%s,%i

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.