📄 2.4.htm
字号:
<P class=docText>Octal notation (<TT><I>n</I></TT> being
0-7)</P></TD></TR>
<TR>
<TD class=docTableCell><PRE>\xnn</PRE></TD>
<TD class=docTableCell>
<P class=docText>Hexadecimal notation (<TT><I>n</I></TT>
being 0-9, a-f, or A-F) </P></TD></TR>
<TR>
<TD class=docTableCell><PRE>\cx, \C-x</PRE></TD>
<TD class=docTableCell>
<P class=docText>Control-<TT><I>x</I></TT></P></TD></TR>
<TR>
<TD class=docTableCell><PRE>\M-x</PRE></TD>
<TD class=docTableCell>
<P class=docText>Meta-x (<TT><I>c</I></TT> |
0x80)</P></TD></TR>
<TR>
<TD class=docTableCell><PRE>\M-\C-x</PRE></TD>
<TD class=docTableCell>
<P
class=docText>Meta-Control-<TT><I>x</I></TT></P></TD></TR>
<TR>
<TD class=docTableCell><PRE>\x</PRE></TD>
<TD class=docTableCell>
<P class=docText>Character
<TT><I>x</I></TT></P></TD></TR></COLGROUP></TBODY></TABLE></P><A
name=IXT-2-126918></A><A name=IXT-2-126919></A>
<DL class=docList>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>`command`</SPAN></SPAN></SPAN>
<DD>
<P class=docList><A name=IXT-2-126918></A><A
name=IXT-2-126919></A>Converts command output to a string.
Allows substitution and backslash notation </P></DD></DL><A
name=ruby-CHP-2-SECT-4.2.4></A>
<H5 class=docSection3Title>2.4.2.4 General delimited
strings</H5><A name=IXT-2-126920></A>
<P class=docText><A name=IXT-2-126921></A><A
name=IXT-2-126922></A><A name=IXT-2-126923></A><A
name=IXT-2-126924></A>The delimiter <TT>!</TT> in expressions
like this: <TT>%q!...!</TT> can be an arbitrary character. If
the delimiter is any of the following: <TT>(</TT> <TT>[</TT>
<TT>{</TT> <TT><</TT>, the end delimiter becomes the
corresponding closing delimiter, allowing for nested delimiter
pairs. </P><A name=IXT-2-126925></A>
<DL class=docList>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>%!foo!</SPAN></SPAN></SPAN>
<DD>
<P class=docList></P>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>%Q!foo!</SPAN></SPAN></SPAN>
<DD>
<P class=docList><A name=IXT-2-126925></A>Equivalent to
double quoted string <TT>"foo"</TT> </P>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>%q!foo!</SPAN></SPAN></SPAN>
<DD>
<P class=docList>Equivalent to single quoted string
<TT>'foo'</TT></P>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>%x!foo!</SPAN></SPAN></SPAN>
<DD>
<P class=docList>Equivalent to <TT>`foo`</TT> command
output</P></DD></DL><A name=ruby-CHP-2-SECT-4.2.5></A>
<H5 class=docSection3Title>2.4.2.5 here documents</H5><A
name=IXT-2-126926></A>
<P class=docText>Builds strings from multiple lines. Contents
span from next logical line to the line that starts with the
delimiter. </P><PRE><<FOO
FOO</PRE>
<P class=docText><A name=IXT-2-126927></A>Using quoted
delimiters after <<, you can specify the quoting
mechanism used for <TT>String</TT> literals. If a minus sign
appears between << and the delimiter, you can indent the
delimiter, as shown here: </P><PRE>puts <<FOO # String in double quotes ("")
hello world
FOO
puts <<"FOO" # String in double quotes ("")
hello world
FOO
puts <<'FOO' # String in single quotes ('')
hello world
FOO
puts <<`FOO` # String in backquotes (``)
hello world
FOO
puts <<-FOO # Delimiter can be indented
hello world
FOO</PRE><A name=ruby-CHP-2-SECT-4.3></A>
<H4 class=docSection2Title>2.4.3 Symbols</H4>
<P class=docText><A name=IXT-2-126928></A><A
name=IXT-2-126929></A>A symbol is an object corresponding to
an identifier or variable: </P><PRE>:foo # symbol for 'foo'
:$foo # symbol for variable '$foo'</PRE><A
name=ruby-CHP-2-SECT-4.4></A>
<H4 class=docSection2Title>2.4.4 Arrays</H4><A
name=IXT-2-126930></A>
<P class=docText><A name=IXT-2-126931></A>An array is a
container class that holds a collection of objects indexed by
an integer. Any kind of object may be stored in an array, and
any given array can store a heterogeneous mix of object types.
Arrays grow as you add elements. Arrays can be created using
<TT>array.new</TT> or via literals. An array expression is a
series of values between brackets <TT>[ ]</TT>: </P>
<DL class=docList>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>[]</SPAN></SPAN></SPAN>
<DD>
<P class=docList>An empty array (with no elements)</P>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>[1, 2, 3]</SPAN></SPAN></SPAN>
<DD>
<P class=docList>An array of three elements</P>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>[1, [2, 3]]</SPAN></SPAN></SPAN>
<DD>
<P class=docList>A nested array</P></DD></DL><A
name=ruby-CHP-2-SECT-4.4.1></A>
<H5 class=docSection3Title>2.4.4.1 General delimited string
array</H5><A name=IXT-2-126932></A>
<P class=docText><A name=IXT-2-126933></A>You can construct
arrays of strings using the shortcut notation, <TT>%W</TT>.
Only whitespace characters and closing parentheses can be
escaped in the following notation: </P><PRE>%w(foo bar baz) # ["foo", "bar", "baz"]</PRE><A
name=ruby-CHP-2-SECT-4.5></A>
<H4 class=docSection2Title>2.4.5 Hashes</H4><A
name=IXT-2-126934></A>
<P class=docText>A hash is a collection of key-value pairs or
a collection that is indexed by arbitrary types of objects.
</P>
<P class=docText>A hash expression is a series of
<TT>key=>value</TT> pairs between braces. </P><PRE>{key1 => val1, key2 => val2}</PRE><A
name=ruby-CHP-2-SECT-4.6></A>
<H4 class=docSection2Title>2.4.6 Regular Expressions</H4><A
name=IXT-2-126935></A>
<P class=docText><A name=IXT-2-126936></A><A
name=IXT-2-126937></A>Regular expressions are a minilanguage
used to describe patterns of strings. A regular expression
literal is a pattern between slashes or between arbitrary
delimiters followed by <TT>%r</TT>: </P><PRE>/pattern/
/pattern/im # option can be specified
%r!/usr/local! # general delimited regular expression</PRE>
<P class=docText><A name=IXT-2-126938></A>Regular expressions
have their own power and mystery; for more on this topic, see
O'Reilly's <SPAN class=docEmphasis>Mastering Regular
Expressions</SPAN> by Jeffrey E.F. Friedl. </P><A
name=ruby-CHP-2-SECT-4.6.1></A>
<H5 class=docSection3Title>2.4.6.1 Regular-expression
modifiers</H5>
<P class=docText>Regular expression literals may include an
optional modifier to control various aspects of matching. The
modifier is specified after the second slash character, as
shown previously and may be represented by one of these
characters: </P>
<DL class=docList>
<DT><I><SPAN class=docPubcolor>i</SPAN></I>
<DD>
<P class=docList>Case-insensitive<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -