Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It depends on how you define "everything". I personally would never claim that each individual concept in ruby is an object. I suppose there isn't really a good definition to describe how ruby works. I think you just have to accept the way ruby does it, which will become plain as you use it.</p> <p>If you want to see if something is an object, try assigning it to a variable, or calling a method on it. You'll get an error if you try to do that with an operator. A notable exception is methods, which aren't objects but return objects.</p> <p>Note that the concept of an object is somewhat abstract. Two variables can point to the same object. Every object is represented by an <code>object_id</code>. You might think of an object_id like a location in memory. Or, you can think of an object as a house, and multiple address books can contain the house's address.</p> <pre><code># point 2 variables to the same object &gt;&gt; s = t = 's' =&gt; "s" &gt;&gt; s.object_id =&gt; 70269794388360 &gt;&gt; t.object_id =&gt; 70269794388360 # get the object by id (for demonstration only; I don't recommend using this in application code) &gt;&gt; ObjectSpace._id2ref(70269794388360) =&gt; "s" # modifying the object. both variables "see" the change &gt;&gt; s &lt;&lt; '_' =&gt; "s_" &gt;&gt; t =&gt; "s_" </code></pre> <p>Continuing the house analogy, appending to a string via <code>&lt;&lt;</code> is like bringing a new chair into the house. Everyone who follows their address book to that house (using the address) will see that the house (object) has the new chair.</p> <p>The ruby language designers did not see a reason to allow treating operators like <code>&amp;&amp;</code> as objects. Can you see any reason to allow it?</p>
 

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