Linux heracles.o2switch.net 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
/
opt
/
alt
/
ruby21
/
share
/
ri
/
2.1.0
/
system
/
syntax
/
//opt/alt/ruby21/share/ri/2.1.0/system/syntax/page-literals_rdoc.ri
U:RDoc::TopLevel[ i I"syntax/literals.rdoc:EFcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[�S: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"Booleans and nil;To;;0;[o; ;[I"Numbers;To;;0;[o; ;[I"Strings;To;;0;[o; ;[I"Symbols;To;;0;[o; ;[I"Arrays;To;;0;[o; ;[I"Hashes;To;;0;[o; ;[I"Ranges;To;;0;[o; ;[I"Regular Expressions;To;;0;[o; ;[I" Procs;T@ S; ; i;I"Booleans and nil;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@ o; ;[I"P(There are also the constants +TRUE+, +FALSE+ and +NIL+, but the lowercase ;TI""literal forms are preferred.);T@ S; ; i;I"Numbers;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"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@ 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"Strings;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"TDouble-quote strings allow escaped characters such as <tt>\n</tt> for newline, ;TI"<tt>\t</tt> for tab, etc.;T@ o; ;[I"DDouble-quote 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"JInterpolation may be disabled by escaping the "#" character or using ;TI"single-quote strings:;T@ o;;[I" '#{1 + 1}' #=> "\#{1 + 1}" ;T;0o; ;[I"TIn addition to disabling interpolation, single-quoted strings also disable all ;TI"@escape sequences except for the single-quote (<tt>\'</tt>).;T@ o; ;[I"2You may also create strings using <tt>%</tt>:;T@ o;;[I"+%(1 + 1 is #{1 + 1}) #=> "1 + 1 is 2" ;T;0o; ;[ I"RThere are two different types of <tt>%</tt> strings <tt>%q(...)</tt> behaves ;TI"Olike a single-quote string (no interpolation or character escaping) while ;TI"R<tt>%Q</tt> behaves as a double-quote string. See Percent Strings below for ;TI"6more discussion of the syntax of percent strings.;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"Here Documents;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"PNote that the 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"MA heredoc allows interpolation and escaped characters. You may disable ;TI"Rinterpolation and escaping by surrounding the opening identifier with single ;TI"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"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"Symbols;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"2You may also create symbols by interpolation:;T@ o;;[I":"my_symbol1" ;TI":"my_symbol#{1 + 1}" ;T;0o; ;[I"RNote that symbols are never garbage collected so be careful when referencing ;TI"!symbols using interpolation.;T@ o; ;[I"GLike strings, a single-quote may be used to disable interpolation:;T@ o;;[I"4:'my_symbol#{1 + 1}' #=> :"my_symbol\#{1 + 1}" ;T;0o; ;[I"PWhen creating a Hash there is a special syntax for referencing a Symbol as ;TI" well.;T@ S; ; i;I"Arrays;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"9See Array for the methods you may use with an array.;T@ S; ; i;I"Hashes;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"6See Hash for the methods you may use with a hash.;T@ S; ; i;I"Ranges;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 ;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"Regular Expressions;T@ o; ;[I"/A regular expression is created using "/":;T@ o;;[I"/my regular expression/ ;T;0o; ;[I"OThe regular expression may be followed by flags which adjust the matching ;TI"Tbehavior of the regular expression. The "i" flag makes the regular expression ;TI"case-insensitive:;T@ o;;[I"/my regular expression/i ;T;0o; ;[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"GSee Regexp for a description of the syntax of regular expressions.;T@ S; ; i;I" Procs;T@ o; ;[I",A 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 Strings;T@ o; ;[I"OBesides <tt>%(...)</tt> which creates a String, The <tt>%</tt> may create ;TI"Iother types of object. As with strings, an uppercase letter allows ;TI"Qinterpolation and escaped characters while a lowercase letter disables them.;T@ o; ;[I"4These are the types of percent strings in ruby:;T@ o;;: NOTE;[o;;[I"<tt>%i</tt> ;T;[o; ;[I"Array of Symbols;To;;[I"<tt>%q</tt> ;T;[o; ;[I"String;To;;[I"<tt>%r</tt> ;T;[o; ;[I"Regular Expression;To;;[I"<tt>%s</tt> ;T;[o; ;[I"Symbol;To;;[I"<tt>%w</tt> ;T;[o; ;[I"Array of Strings;To;;[I"<tt>%x</tt> ;T;[o; ;[I"'Backtick (capture subshell result);T@ o; ;[I"RFor the two array forms of percent string, if you wish to include a space in ;TI"Gone of the array entries you must escape it with a "\\" character:;T@ o;;[I"%w[one one-hundred\ one] ;TI"$#=> ["one", "one-hundred one"] ;T;0o; ;[I"SIf you are using "(", "[", "{", "<" you must close it with ")", "]", "}", ">" ;TI"Srespectively. You may use most other non-alphanumeric characters for percent ;TI"2string delimiters such as "%", "|", "^", etc.;T: @file@:0@omit_headings_from_table_of_contents_below0