Posts

Showing posts from December, 2008

print what you like

The following web site allows you to select part of a page, or edit a page to help you print in a way you like: http://www.printwhatyoulike.com

Comparison of equality operators in Ruby: == vs. equal? vs. eql? vs. ===

Here is a short explanation of when these predicates are true (From http://www.wellho.net/mouth/985_Equality-in-Ruby-eql-and-equal-.html) The == comparison checks whether two values are equal eql? checks if two values are equal and of the same type equal? checks if two things are one and the same object. How do I remember which is which ... The longer the operator, the more restrictive the test it performs Let's understand the differences with some examples. Each "abc" below is a different object. Therefore, equal? is false. irb(main):065:0> "abc".object_id => 24173330 irb(main):066:0> "abc".object_id => 24165760 irb(main):067:0> "abc" == "abc" => true irb(main):068:0> "abc".eql? "abc" => true irb(main):069:0> "abc".equal? "abc" => false As you might expect, there is a single instance of 1. Therefore, all comparisons are true. irb(main):094:0> 1.class =>