Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The assignment operator in the Ruby Language allow <a href="http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Operators" rel="nofollow">Multiple assignments</a> (aka: parallel assignment). </p> <p>Say <em>lvalue</em> the left side variables or attributes on the left side of the assignment operator (=) and say <em>rvalue</em> the right side values. </p> <p>By <em>Multiple assignments</em> you can assign one comma delimited list to another, with corresponding variables on the left side getting corresponding values from the right</p> <h3>first parallel assignment</h3> <pre><code>a, b = ["ho", "hey"] </code></pre> <p>if the last <em>rvalue</em> is an array, you can prefix it with an asterisk, which <strong>effectively expands it into its constituent values in place</strong>. the asterisk is not necessary if the <em>rvalue</em> is the only thing on the right-hand side <strong>the array will be expanded automatically</strong>.</p> <p>To better understand, try this:</p> <pre><code>&gt;&gt; a,b,c = "1",*["ho", "hey"] =&gt; ["1", "ho", "hey"] &gt;&gt; a =&gt; "1" &gt;&gt; b =&gt; "ho" &gt;&gt; c =&gt; "hey" </code></pre> <p>let's see again:</p> <pre><code>&gt;&gt; a,b,c = "1",["ho", "hey"] =&gt; ["1", ["ho", "hey"]] &gt;&gt; a =&gt; "1" &gt;&gt; b =&gt; ["ho", "hey"] &gt;&gt; c =&gt; nil </code></pre> <p>as you can see, if we don't prefix the array with the * then the array is not expanded.</p> <h3>second parallel assignment</h3> <pre><code>c, d = "foo", "bar" </code></pre> <p>"foo", "bar" are two <a href="http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals" rel="nofollow"><strong>literal Strings</strong></a> assigned to the corresponding variable on the left side.</p> <h3>third parallel assignment</h3> <pre><code>a, b = ["blerg"], ["baz"])? </code></pre> <p><code>["blerg"]</code> and <code>["baz"]</code> are two <strong>Array</strong> each one containing one element of class <strong>String</strong>;</p> <p>therefore each "Array of a sigle String" is assigned to the corresponding variable on the left side.</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. This table or related slice is empty.
    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