D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
syntax
/
Filename :
page-literals_rdoc.ri
back
Copy
U:RDoc::TopLevel[ i I"syntax/literals.rdoc:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[0S:RDoc::Markup::Heading: leveli: textI" Literals;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[I"LLiterals create objects you can use in your program. Literals include:;T@ o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o; ;[I"@{Boolean and Nil Literals}[#label-Boolean+and+Nil+Literals];To;;0;[o; ;[I".{Number Literals}[#label-Number+Literals];T@ o;;;;[ o;;0;[o; ;[I"0{Integer Literals}[#label-Integer+Literals];To;;0;[o; ;[I",{Float Literals}[#label-Float+Literals];To;;0;[o; ;[I"2{Rational Literals}[#label-Rational+Literals];To;;0;[o; ;[I"0{Complex Literals}[#label-Complex+Literals];T@ o;;0;[o; ;[I".{String Literals}[#label-String+Literals];To;;0;[o; ;[I"<{Here Document Literals}[#label-Here+Document+Literals];To;;0;[o; ;[I".{Symbol Literals}[#label-Symbol+Literals];To;;0;[o; ;[I",{Array Literals}[#label-Array+Literals];To;;0;[o; ;[I"*{Hash Literals}[#label-Hash+Literals];To;;0;[o; ;[I",{Range Literals}[#label-Range+Literals];To;;0;[o; ;[I".{Regexp Literals}[#label-Regexp+Literals];To;;0;[o; ;[I"8{Lambda Proc Literals}[#label-Lambda+Proc+Literals];To;;0;[o; ;[I"0{Percent Literals}[#label-Percent+Literals];T@ o;;;;[o;;0;[o; ;[I"[{%q: Non-Interpolable String Literals}[#label-25q-3A+Non-Interpolable+String+Literals];To;;0;[o; ;[I"a{% and %Q: Interpolable String Literals}[#label-25+and+-25Q-3A+Interpolable+String+Literals];To;;0;[o; ;[I"U{%w and %W: String-Array Literals}[#label-25w+and+-25W-3A+String-Array+Literals];To;;0;[o; ;[I"U{%i and %I: Symbol-Array Literals}[#label-25i+and+-25I-3A+Symbol-Array+Literals];To;;0;[o; ;[I"9{%r: Regexp Literals}[#label-25r-3A+Regexp+Literals];To;;0;[o; ;[I"9{%s: Symbol Literals}[#label-25s-3A+Symbol+Literals];To;;0;[o; ;[I"={%x: Backtick Literals}[#label-25x-3A+Backtick+Literals];T@ S; ; i;I"Boolean and Nil Literals;T@ o; ;[I"S+nil+ and +false+ are both false values. +nil+ is sometimes used to indicate ;TI"Q"no value" or "unknown" but evaluates to +false+ in conditional expressions.;T@ o; ;[I"Q+true+ is a true value. All objects except +nil+ and +false+ evaluate to a ;TI"+true value in conditional expressions.;T@ S; ; i;I"Number Literals;T@ S; ; i;I"\Integer Literals;T@ o; ;[I"3You can write integers of any size as follows:;T@ o:RDoc::Markup::Verbatim;[I" 1234 ;TI"1_234 ;T:@format0o; ;[I"NThese numbers have the same value, 1,234. The underscore may be used to ;TI"Renhance readability for humans. You may place an underscore anywhere in the ;TI"number.;T@ o; ;[ I"RYou can use a special prefix to write numbers in decimal, hexadecimal, octal ;TI"Nor binary formats. For decimal numbers use a prefix of <tt>0d</tt>, for ;TI"Nhexadecimal numbers use a prefix of <tt>0x</tt>, for octal numbers use a ;TI"Mprefix of <tt>0</tt> or <tt>0o</tt>, for binary numbers use a prefix of ;TI"P<tt>0b</tt>. The alphabetic component of the number is not case-sensitive.;T@ o; ;[I"Examples:;T@ o;;[I"0d170 ;TI"0D170 ;TI" ;TI" 0xaa ;TI" 0xAa ;TI" 0xAA ;TI" 0Xaa ;TI" 0XAa ;TI" 0XaA ;TI" ;TI" 0252 ;TI"0o252 ;TI"0O252 ;TI" ;TI"0b10101010 ;TI"0B10101010 ;T;0o; ;[I"SAll these numbers have the same decimal value, 170. Like integers and floats ;TI"/you may use an underscore for readability.;T@ S; ; i;I"\Float Literals;T@ o; ;[I"6Floating-point numbers may be written as follows:;T@ o;;[I"12.34 ;TI" 1234e-2 ;TI" 1.234E1 ;T;0o; ;[I"TThese numbers have the same value, 12.34. You may use underscores in floating ;TI"point numbers as well.;T@ S; ; i;I"\Rational Literals;T@ o; ;[I"KYou can write a Rational literal using a special suffix, <tt>'r'</tt>.;T@ o; ;[I"Examples:;T@ o;;[I"1r # => (1/1) ;TI"/2/3r # => (2/3) # With denominator. ;TI")-1r # => (-1/1) # With signs. ;TI"-2/3r # => (-2/3) ;TI"2/-3r # => (-2/3) ;TI"-2/-3r # => (2/3) ;TI"+1/+3r # => (1/3) ;TI"31.2r # => (6/5) # With fractional part. ;TI"81_1/2_1r # => (11/21) # With embedded underscores. ;TI"42/4r # => (1/2) # Automatically reduced. ;T;0o; ;[I"Syntax:;T@ o;;[I"@<rational-literal> = <numerator> [ '/' <denominator> ] 'r' ;TI"=<numerator> = [ <sign> ] <digits> [ <fractional-part> ] ;TI"&<fractional-part> = '.' <digits> ;TI"'<denominator> = [ sign ] <digits> ;TI"<sign> = '-' | '+' ;TI"2<digits> = <digit> { <digit> | '_' <digit> } ;TI"I<digit> = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;T;0o; ;[I"ANote this, which is parsed as \Float numerator <tt>1.2</tt> ;TI"3divided by \Rational denominator <tt>3r</tt>, ;TI"resulting in a \Float:;T@ o;;[I"&1.2/3r # => 0.39999999999999997 ;T;0S; ; i;I"\Complex Literals;T@ o; ;[I">You can write a Complex number as follows (suffixed +i+):;T@ o;;[I"1i #=> (0+1i) ;TI"1i * 1i #=> (-1+0i) ;T;0o; ;[I"5Also \Rational numbers may be imaginary numbers.;T@ o;;[I"$12.3ri #=> (0+(123/10)*i) ;T;0o; ;[I"?+i+ must be placed after +r+; the opposite is not allowed.;T@ o;;[I""12.3ir #=> Syntax error ;T;0S; ; i;I"Strings;T@ S; ; i;I"Escape Sequences;T@ o; ;[ I"?Some characters can be represented as escape sequences in ;TI"double-quoted strings, ;TI"character literals, ;TI"Mhere document literals (non-quoted, double-quoted, and with backticks), ;TI"double-quoted symbols, ;TI"1double-quoted symbol keys in Hash literals, ;TI"Regexp literals, and ;TI"lseveral percent literals (<tt>%</tt>, <tt>%Q</tt>, <tt>%W</tt>, <tt>%I</tt>, <tt>%r</tt>, <tt>%x</tt>).;T@ o; ;[I"9They allow escape sequences such as <tt>\n</tt> for ;TI"Knewline, <tt>\t</tt> for tab, etc. The full list of supported escape ;TI"sequences are as follows:;T@ o;;[I"*\a bell, ASCII 07h (BEL) ;TI".\b backspace, ASCII 08h (BS) ;TI"4\t horizontal tab, ASCII 09h (TAB) ;TI"8\n newline (line feed), ASCII 0Ah (LF) ;TI"1\v vertical tab, ASCII 0Bh (VT) ;TI".\f form feed, ASCII 0Ch (FF) ;TI"4\r carriage return, ASCII 0Dh (CR) ;TI",\e escape, ASCII 1Bh (ESC) ;TI"+\s space, ASCII 20h (SPC) ;TI"!\\ backslash, \ ;TI"M\nnn octal bit pattern, where nnn is 1-3 octal digits ([0-7]) ;TI"^\xnn hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F]) ;TI"`\unnnn Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F]) ;TI"b\u{nnnn ...} Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F]) ;TI"O\cx or \C-x control character, where x is an ASCII printable character ;TI"L\M-x meta character, where x is an ASCII printable character ;TI"T\M-\C-x meta control character, where x is an ASCII printable character ;TI""\M-\cx same as above ;TI""\c\M-x same as above ;TI",\c? or \C-? delete, ASCII 7Fh (DEL) ;TI"5\<newline> continuation line (empty string) ;T;0o; ;[I"[The last one, <tt>\<newline></tt>, represents an empty string instead of a character. ;TI"+It is used to fold a line in a string.;T@ S; ; i;I"#Double-Quoted \String Literals;T@ o; ;[I"@The most common way of writing strings is using <tt>"</tt>:;T@ o;;[I""This is a string." ;T;0o; ;[I"'The string may be many lines long.;T@ o; ;[I"-Any internal <tt>"</tt> must be escaped:;T@ o;;[I"C"This string has a quote: \". As you can see, it is escaped" ;T;0o; ;[I"?Double-quoted strings allow escape sequences described in ;TI"1{Escape Sequences}[#label-Escape+Sequences].;T@ o; ;[I" In a double-quoted string, ;TI"Eany other character following a backslash is interpreted as the ;TI"character itself.;T@ o; ;[I"EDouble-quoted strings allow interpolation of other values using ;TI"<tt>#{...}</tt>:;T@ o;;[I"%"One plus one is two: #{1 + 1}" ;T;0o; ;[I"TAny expression may be placed inside the interpolated section, but it's best to ;TI"/keep the expression small for readability.;T@ o; ;[I"NYou can also use <tt>#@foo</tt>, <tt>#@@foo</tt> and <tt>#$foo</tt> as a ;TI"Nshorthand for, respectively, <tt>#{ @foo }</tt>, <tt>#{ @@foo }</tt> and ;TI"<tt>#{ $foo }</tt>.;T@ o; ;[I"See also:;T@ o;;;;[o;;0;[o; ;[I"a{% and %Q: Interpolable String Literals}[#label-25+and+-25Q-3A+Interpolable+String+Literals];T@ S; ; i;I"#Single-Quoted \String Literals;T@ o; ;[I"JInterpolation may be disabled by escaping the "#" character or using ;TI"single-quoted strings:;T@ o;;[I" '#{1 + 1}' #=> "\#{1 + 1}" ;T;0o; ;[I"TIn addition to disabling interpolation, single-quoted strings also disable all ;TI"Nescape sequences except for the single-quote (<tt>\'</tt>) and backslash ;TI"(<tt>\\\\</tt>).;T@ o; ;[I" In a single-quoted string, ;TI"Eany other character following a backslash is interpreted as is: ;TI"*a backslash and the character itself.;T@ o; ;[I"See also:;T@ o;;;;[o;;0;[o; ;[I"[{%q: Non-Interpolable String Literals}[#label-25q-3A+Non-Interpolable+String+Literals];T@ S; ; i;I"!Literal String Concatenation;T@ o; ;[I"PAdjacent string literals are automatically concatenated by the interpreter:;T@ o;;[I"5"con" "cat" "en" "at" "ion" #=> "concatenation" ;TI""This string contains "\ ;TI"I"no newlines." #=> "This string contains no newlines." ;T;0o; ;[I"RAny combination of adjacent single-quote, double-quote, percent strings will ;TI"=be concatenated as long as a percent-string is not last.;T@ o;;[I"%q{a} 'b' "c" #=> "abc" ;TI";"a" 'b' %q{c} #=> NameError: uninitialized constant q ;T;0S; ; i;I"Character Literal;T@ o; ;[ I"DThere is also a character literal notation to represent single ;TI"Echaracter strings, which syntax is a question mark (<tt>?</tt>) ;TI"Rfollowed by a single character or escape sequence (except continuation line) ;TI"Cthat corresponds to a single codepoint in the script encoding:;T@ o;;[I"?a #=> "a" ;TI"?abc #=> SyntaxError ;TI"?\n #=> "\n" ;TI"?\s #=> " " ;TI"?\\ #=> "\\" ;TI"?\u{41} #=> "A" ;TI"?\C-a #=> "\x01" ;TI"?\M-a #=> "\xE1" ;TI"?\M-\C-a #=> "\x81" ;TI"(?\C-\M-a #=> "\x81", same as above ;TI"?あ #=> "あ" ;T;0S; ; i;I"Here Document Literals;T@ o; ;[I"OIf you are writing a large block of text you may use a "here document" or ;TI""heredoc":;T@ o;;[ I"!expected_result = <<HEREDOC ;TI"2This would contain specially formatted text. ;TI" ;TI" That might span many lines ;TI" HEREDOC ;T;0o; ;[I"SThe heredoc starts on the line following <tt><<HEREDOC</tt> and ends with the ;TI"Rnext line that starts with <tt>HEREDOC</tt>. The result includes the ending ;TI" newline.;T@ o; ;[I"RYou may use any identifier with a heredoc, but all-uppercase identifiers are ;TI"typically used.;T@ o; ;[I"OYou may indent the ending identifier if you place a "-" after <tt><<</tt>:;T@ o;;[ I"- expected_result = <<-INDENTED_HEREDOC ;TI"2This would contain specially formatted text. ;TI" ;TI" That might span many lines ;TI" INDENTED_HEREDOC ;T;0o; ;[I"LNote that while the closing identifier may be indented, the content is ;TI"Talways treated as if it is flush left. If you indent the content those spaces ;TI"will appear in the output.;T@ o; ;[I"UTo have indented content as well as an indented closing identifier, you can use ;TI"Oa "squiggly" heredoc, which uses a "~" instead of a "-" after <tt><<</tt>:;T@ o;;[ I"+expected_result = <<~SQUIGGLY_HEREDOC ;TI"4 This would contain specially formatted text. ;TI" ;TI"" That might span many lines ;TI"SQUIGGLY_HEREDOC ;T;0o; ;[ I"RThe indentation of the least-indented line will be removed from each line of ;TI"Uthe content. Note that empty lines and lines consisting solely of literal tabs ;TI"Qand spaces will be ignored for the purposes of determining indentation, but ;TI"Gescaped tabs and spaces are considered non-indentation characters.;T@ o; ;[ I"TFor the purpose of measuring an indentation, a horizontal tab is regarded as a ;TI"Tsequence of one to eight spaces such that the column position corresponding to ;TI"Sits end is a multiple of eight. The amount to be removed is counted in terms ;TI"Tof the number of spaces. If the boundary appears in the middle of a tab, that ;TI"tab is not removed.;T@ o; ;[ I"JA heredoc allows interpolation and the escape sequences described in ;TI"2{Escape Sequences}[#label-Escape+Sequences]. ;TI"OYou may disable interpolation and the escaping by surrounding the opening ;TI"#identifier with single quotes:;T@ o;;[ I"%expected_result = <<-'EXPECTED' ;TI"One plus one is #{1 + 1} ;TI"EXPECTED ;TI" ;TI"?p expected_result # prints: "One plus one is \#{1 + 1}\n" ;T;0o; ;[I"TThe identifier may also be surrounded with double quotes (which is the same as ;TI"Mno quotes) or with backticks. When surrounded by backticks the HEREDOC ;TI"behaves like Kernel#`:;T@ o;;[I"puts <<-`HEREDOC` ;TI"cat #{__FILE__} ;TI" HEREDOC ;T;0o; ;[I"LWhen surrounding with quotes, any character but that quote and newline ;TI"2(CR and/or LF) can be used as the identifier.;T@ o; ;[I"ITo call a method on a heredoc place it after the opening identifier:;T@ o;;[I")expected_result = <<-EXPECTED.chomp ;TI"One plus one is #{1 + 1} ;TI"EXPECTED ;T;0o; ;[I"SYou may open multiple heredocs on the same line, but this can be difficult to ;TI" read:;T@ o;;[ I"puts(<<-ONE, <<-TWO) ;TI"content for heredoc one ;TI" ONE ;TI"content for heredoc two ;TI" TWO ;T;0S; ; i;I"\Symbol Literals;T@ o; ;[I"RA Symbol represents a name inside the ruby interpreter. See Symbol for more ;TI"Gdetails on what symbols are and when ruby creates them internally.;T@ o; ;[I"CYou may reference a symbol using a colon: <tt>:my_symbol</tt>.;T@ o; ;[I"TYou may also create symbols by interpolation and escape sequences described in ;TI"D{Escape Sequences}[#label-Escape+Sequences] with double-quotes:;T@ o;;[I":"my_symbol1" ;TI":"my_symbol#{1 + 1}" ;TI":"foo\sbar" ;T;0o; ;[I"KLike strings, a single-quote may be used to disable interpolation and ;TI"escape sequences:;T@ o;;[I"4:'my_symbol#{1 + 1}' #=> :"my_symbol\#{1 + 1}" ;T;0o; ;[I"QWhen creating a Hash, there is a special syntax for referencing a Symbol as ;TI" well.;T@ o; ;[I"See also:;T@ o;;;;[o;;0;[o; ;[I"9{%s: Symbol Literals}[#label-25s-3A+Symbol+Literals];T@ S; ; i;I"\Array Literals;T@ o; ;[I"MAn array is created using the objects between <tt>[</tt> and <tt>]</tt>:;T@ o;;[I"[1, 2, 3] ;T;0o; ;[I"0You may place expressions inside the array:;T@ o;;[I"[1, 1 + 1, 1 + 2] ;TI"[1, [1 + 1, [1 + 2]]] ;T;0o; ;[I"See also:;T@ o;;;;[o;;0;[o; ;[I"U{%w and %W: String-Array Literals}[#label-25w+and+-25W-3A+String-Array+Literals];To;;0;[o; ;[I"U{%i and %I: Symbol-Array Literals}[#label-25i+and+-25I-3A+Symbol-Array+Literals];T@ o; ;[I"9See Array for the methods you may use with an array.;T@ S; ; i;I"\Hash Literals;T@ o; ;[I"OA hash is created using key-value pairs between <tt>{</tt> and <tt>}</tt>:;T@ o;;[I"{ "a" => 1, "b" => 2 } ;T;0o; ;[I".Both the key and value may be any object.;T@ o; ;[I"GYou can create a hash using symbol keys with the following syntax:;T@ o;;[I"{ a: 1, b: 2 } ;T;0o; ;[I"AThis same syntax is used for keyword arguments for a method.;T@ o; ;[I"5Like Symbol literals, you can quote symbol keys.;T@ o;;[I"#{ "a 1": 1, "b #{1 + 1}": 2 } ;T;0o; ;[I"is equal to;T@ o;;[I""{ :"a 1" => 1, :"b 2" => 2 } ;T;0o; ;[I"UHash values can be omitted, meaning that value will be fetched from the context ;TI"by the name of the key:;T@ o;;[ I" x = 100 ;TI" y = 200 ;TI"h = { x:, y: } ;TI"#=> {:x=>100, :y=>200} ;T;0o; ;[I"6See Hash for the methods you may use with a hash.;T@ S; ; i;I"\Range Literals;T@ o; ;[I"QA range represents an interval of values. The range may include or exclude ;TI"its ending value.;T@ o;;[ I")(1..2) # includes its ending value ;TI")(1...2) # excludes its ending value ;TI"P(1..) # endless range, representing infinite sequence from 1 to Infinity ;TI"S(..1) # beginless range, representing infinite sequence from -Infinity to 1 ;T;0o; ;[I"TYou may create a range of any object. See the Range documentation for details ;TI"*on the methods you need to implement.;T@ S; ; i;I"\Regexp Literals;T@ o; ;[I"DA regular expression may be created using leading and trailing ;TI"%slash (<tt>'/'</tt>) characters:;T@ o;;[I"re = /foo/ # => /foo/ ;TI"re.class # => Regexp ;T;0o; ;[I"LThe trailing slash may be followed by one or more modifiers characters ;TI"$that set modes for the regexp. ;TI";See {Regexp modes}[rdoc-ref:Regexp@Modes] for details.;T@ o; ;[I"MInterpolation may be used inside regular expressions along with escaped ;TI"Pcharacters. Note that a regular expression may require additional escaped ;TI"characters than a string.;T@ o; ;[I"See also:;T@ o;;;;[o;;0;[o; ;[I"9{%r: Regexp Literals}[#label-25r-3A+Regexp+Literals];T@ o; ;[I"GSee Regexp for a description of the syntax of regular expressions.;T@ S; ; i;I"Lambda Proc Literals;T@ o; ;[I"3A lambda proc can be created with <tt>-></tt>:;T@ o;;[I"-> { 1 + 1 } ;T;0o; ;[I"=Calling the above proc will give a result of <tt>2</tt>.;T@ o; ;[I"7You can require arguments for the proc as follows:;T@ o;;[I"->(v) { 1 + v } ;T;0o; ;[I",This proc will add one to its argument.;T@ S; ; i;I"Percent Literals;T@ o; ;[I"7Each of the literals in described in this section ;TI"%may use these paired delimiters:;T@ o;;;;[ o;;0;[o; ;[I"<tt>[</tt> and <tt>]</tt>.;To;;0;[o; ;[I"<tt>(</tt> and <tt>)</tt>.;To;;0;[o; ;[I"<tt>{</tt> and <tt>}</tt>.;To;;0;[o; ;[I"<tt><</tt> and <tt>></tt>.;To;;0;[o; ;[I"\Non-alphanumeric ASCII character except above, as both beginning and ending delimiters.;T@ o; ;[ I"5The delimiters can be escaped with a backslash. ;TI"GHowever, the first four pairs (brackets, parenthesis, braces, and ;TI"Pangle brackets) are allowed without backslash as far as they are correctly ;TI"paired.;T@ o; ;[I"0These are demonstrated in the next section.;T@ S; ; i;I"2<tt>%q</tt>: Non-Interpolable String Literals;T@ o; ;[I"?You can write a non-interpolable string with <tt>%q</tt>. ;TI"LThe created string is the same as if you created it with single quotes:;T@ o;;[I":%q[foo bar baz] # => "foo bar baz" # Using []. ;TI":%q(foo bar baz) # => "foo bar baz" # Using (). ;TI":%q{foo bar baz} # => "foo bar baz" # Using {}. ;TI":%q<foo bar baz> # => "foo bar baz" # Using <>. ;TI"=%q|foo bar baz| # => "foo bar baz" # Using two |. ;TI"=%q:foo bar baz: # => "foo bar baz" # Using two :. ;TI"I%q(1 + 1 is #{1 + 1}) # => "1 + 1 is \#{1 + 1}" # No interpolation. ;TI"H%q[foo[bar]baz] # => "foo[bar]baz" # brackets can be nested. ;TI"K%q(foo(bar)baz) # => "foo(bar)baz" # parenthesis can be nested. ;TI"F%q{foo{bar}baz} # => "foo{bar}baz" # braces can be nested. ;TI"N%q<foo<bar>baz> # => "foo<bar>baz" # angle brackets can be nested. ;T;0o; ;[I"FThis is similar to single-quoted string but only backslashes and ;TI">the specified delimiters can be escaped with a backslash.;T@ S; ; i;I"4<tt>% and %Q</tt>: Interpolable String Literals;T@ o; ;[I";You can write an interpolable string with <tt>%Q</tt> ;TI""or with its alias <tt>%</tt>:;T@ o;;[I"-%[foo bar baz] # => "foo bar baz" ;TI"=%(1 + 1 is #{1 + 1}) # => "1 + 1 is 2" # Interpolation. ;T;0o; ;[ I".This is similar to double-quoted string. ;TI",It allow escape sequences described in ;TI"2{Escape Sequences}[#label-Escape+Sequences]. ;TI"HOther escaped characters (a backslash followed by a character) are ;TI""interpreted as the character.;T@ S; ; i;I".<tt>%w and %W</tt>: String-Array Literals;T@ o; ;[I"EYou can write an array of strings as whitespace-separated words ;TI"Gwith <tt>%w</tt> (non-interpolable) or <tt>%W</tt> (interpolable):;T@ o;;[I"6%w[foo bar baz] # => ["foo", "bar", "baz"] ;TI"0%w[1 % *] # => ["1", "%", "*"] ;TI"5# Use backslash to embed spaces in the strings. ;TI"7%w[foo\ bar baz\ bat] # => ["foo bar", "baz bat"] ;TI"7%W[foo\ bar baz\ bat] # => ["foo bar", "baz bat"] ;TI"4%w(#{1 + 1}) # => ["\#{1", "+", "1}"] ;TI"&%W(#{1 + 1}) # => ["2"] ;TI" ;TI"B# The nested delimiters evaluated to a flat array of strings ;TI"# (not nested array). ;TI"7%w[foo[bar baz]qux] # => ["foo[bar", "baz]qux"] ;T;0o; ;[I"OThe following characters are considered as white spaces to separate words:;T@ o;;;;[o;;0;[o; ;[I"space, ASCII 20h (SPC);To;;0;[o; ;[I"form feed, ASCII 0Ch (FF);To;;0;[o; ;[I"(newline (line feed), ASCII 0Ah (LF);To;;0;[o; ;[I"$carriage return, ASCII 0Dh (CR);To;;0;[o; ;[I"$horizontal tab, ASCII 09h (TAB);To;;0;[o; ;[I"!vertical tab, ASCII 0Bh (VT);T@ o; ;[I"MThe white space characters can be escaped with a backslash to make them ;TI"part of a word.;T@ o; ;[ I"5<tt>%W</tt> allow escape sequences described in ;TI"2{Escape Sequences}[#label-Escape+Sequences]. ;TI"MHowever the continuation line <tt>\<newline></tt> is not usable because ;TI">it is interpreted as the escaped newline described above.;T@ S; ; i;I".<tt>%i and %I</tt>: Symbol-Array Literals;T@ o; ;[I"EYou can write an array of symbols as whitespace-separated words ;TI"Gwith <tt>%i</tt> (non-interpolable) or <tt>%I</tt> (interpolable):;T@ o;;[I"3%i[foo bar baz] # => [:foo, :bar, :baz] ;TI"/%i[1 % *] # => [:"1", :%, :*] ;TI"5# Use backslash to embed spaces in the symbols. ;TI"9%i[foo\ bar baz\ bat] # => [:"foo bar", :"baz bat"] ;TI"9%I[foo\ bar baz\ bat] # => [:"foo bar", :"baz bat"] ;TI"5%i(#{1 + 1}) # => [:"\#{1", :+, :"1}"] ;TI"'%I(#{1 + 1}) # => [:"2"] ;T;0o; ;[I"OThe white space characters and its escapes are interpreted as the same as ;TI"(string-array literals described in ;TI"V{%w and %W: String-Array Literals}[#label-25w+and+-25W-3A+String-Array+Literals].;T@ S; ; i;I"!<tt>%s</tt>: Symbol Literals;T@ o; ;[I"-You can write a symbol with <tt>%s</tt>:;T@ o;;[I"%s[foo] # => :foo ;TI"!%s[foo bar] # => :"foo bar" ;T;0o; ;[I"This is non-interpolable. ;TI"No interpolation allowed. ;TI"SOnly backslashes and the specified delimiters can be escaped with a backslash.;T@ S; ; i;I"!<tt>%r</tt>: Regexp Literals;T@ o; ;[I":You can write a regular expression with <tt>%r</tt>; ;TI">the character used as the leading and trailing delimiter ;TI"#may be (almost) any character:;T@ o;;[I"$%r/foo/ # => /foo/ ;TI"1%r:name/value pair: # => /name\/value pair/ ;T;0o; ;[I"CA few "symmetrical" character pairs may be used as delimiters:;T@ o;;[ I"%r[foo] # => /foo/ ;TI"%r{foo} # => /foo/ ;TI"%r(foo) # => /foo/ ;TI"%r<foo> # => /foo/ ;T;0o; ;[I"OThe trailing delimiter may be followed by one or more modifier characters ;TI"$that set modes for the regexp. ;TI";See {Regexp modes}[rdoc-ref:Regexp@Modes] for details.;T@ S; ; i;I"#<tt>%x</tt>: Backtick Literals;T@ o; ;[I"@You can write and execute a shell command with <tt>%x</tt>:;T@ o;;[I" %x(echo 1) # => "1\n" ;TI""%x[echo #{1 + 2}] # => "3\n" ;TI" %x[echo \u0030] # => "0\n" ;T;0o; ;[I"This is interpolable. ;TI"5<tt>%x</tt> allow escape sequences described in ;TI"1{Escape Sequences}[#label-Escape+Sequences].;T: @file@:0@omit_headings_from_table_of_contents_below0