title: Is "==" in Ruby always value equality?
body: <p>Sorry if duplicated (I didn't find it)</p>
  
  <p>This is only to confirm that Ruby's operator <code>==</code> performs always an equality comparison.
  I.e. </p>
  
  <pre><code>a == b
  </code></pre>
  
  <p>compares a's value against b's value, instead than, like Java, whether they point to the same object in memory (For this latter thing, in Ruby, you should use <code>a.object_id == b.object_id</code>).</p>
  
  <p>Thus, as a consequence it is safe to compare string values with == in Ruby (while it is not safe to do so in Java)</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>The question is on the the default == behavior for any Ruby object, as it can mislead Java-C-C++ programmers assuming a==b compares references themselves, not the reference contents.</p>
  
  <p>Anyway,  you can check out this code, using strings</p>
  
  <pre><code>one="hello"
  two="he"
  two &lt;&lt; "llo"
  
  if one == two
    puts "surprise: comparing values, not like in Java"
  end
  
  if not one.object_id == two.object_id
    puts "obvious: do this to compare references"
  end
  </code></pre>
  
  <p><strong>Edit 2</strong>.</p>
  
  <p>So, in Ruby, the comparison</p>
  
  <pre><code>a == b
  </code></pre>
  
  <p>checks  a's and b's values</p>
  
  <p>but, the assignment</p>
  
  <pre><code>a = b
  </code></pre>
  
  <p>does not copy values, but makes a and b point to the same object !</p>
  
  <p>continuing with the previous code</p>
  
  <pre><code>puts one.object_id
  puts two.object_id
  
  puts " and now "
  
  one = two
  
  puts one.object_id
  puts two.object_id
  </code></pre>