Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://www.ruby-doc.org/docs/ProgrammingRuby/" rel="noreferrer">Programming Ruby</a> mentions them in the <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html" rel="noreferrer">chapter about strings</a>.</p> <p>Related to <code>%q{}</code> and <code>%Q{}</code> is <code>%{}</code> which is the same as <code>%Q{}</code>. Also, the delimiters "<code>{}</code>" I show can be a matching pair of delimiters, so you could use <code>[]</code>, <code>()</code>, etc. <code>%q{}</code> is the same as using single-quotes to delimit a string. <code>%Q{}</code> is the same as using double-quotes, allowing embedded strings to be interpolated:</p> <pre><code>%q{foobar} # =&gt; "foobar" %Q{foobar} # =&gt; "foobar" asdf = 'bar' # =&gt; "bar" %q{foo#{asdf}} # =&gt; "foo\#{asdf}" %Q{foo#{asdf}} # =&gt; "foobar" </code></pre> <p>Also, there is <code>%w{}</code> which splits a string using whitespace, into an array. For instance:</p> <pre><code>%w[a b c] # =&gt; ["a", "b", "c"] </code></pre> <p><code>%w{}</code> doesn't interpolate embedded variables:</p> <pre><code>%w[a b asdf] # =&gt; ["a", "b", "asdf"] %w[a b #{asdf}] # =&gt; ["a", "b", "\#{asdf}"] </code></pre> <p>And <code>%r{}</code> which defines a regular expression:</p> <pre><code>%r{^foo}.class # =&gt; Regexp </code></pre> <p>Finally there is <code>%x{}</code> which acts like backticks, i.e. "``", passing the string to the underlying operating system. Think of it as "exec":</p> <pre><code>%x{date} # =&gt; "Fri Nov 26 15:08:44 MST 2010\n" </code></pre> <p>A lot of Ruby's ideas for these shortcuts come from Perl, only in Perl they use <code>q{}</code>, <code>qq{}</code>, <code>qw{}</code>, <code>qx{}</code> and <code>qr{}</code>. The leading <code>q</code> stands for "quote", and they are treated and documented as "quoting" operators if I remember right. Ruby's documentation needs to be expanded, and this particular set of tools could definitely use some help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload