Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

Ruby Programming
Previous Page Home Next Page

General Delimited Input

There are alternative forms of literal strings, arrays, regular expressions, and shell commands that are specified using a generalized delimited syntax. All these literals start with a percent character, followed by a single character that identifies the literal's type. These characters are summarized in Table 18.1 on page 200; the actual literals are described in the corresponding sections later in this chapter.

General delimited input
Type Meaning See Page
%q Single-quoted string 202
%Q, % Double-quoted string 202
%w Array of tokens 204
%r Regular expression pattern 205
%x Shell command 218

Following the type character is a delimiter, which can be any character. If the delimiter is one of the characters ``('', ``['', ``{'', or ``<'', the literal consists of the characters up to the matching closing delimiter, taking account of nested delimiter pairs. For all other delimiters, the literal comprises the characters up to the next occurrence of the delimiter character.

%q/this is a string/
%q-string-
%q(a (nested) string)

Delimited strings may continue over multiple lines.

%q{def fred(a)
     a.each { |i| puts i }
   end}

Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire