Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby "is" equivalent

Tags:

python

ruby

Is there a Ruby equivalent for Python's "is"? It tests whether two objects are identical (i.e. have the same memory location).

like image 549
cdleary Avatar asked Aug 30 '08 03:08

cdleary


People also ask

What is equal in Ruby?

Basic Equality (Double Equals) Ruby has the == and != operators for checking whether two objects are equal or not: "orange" == "red" # => false. 1 + 3 == 4 # => true. 12 - 1 != 10 # => true.

How do I check if a string is equal in Ruby?

Two strings or boolean values, are equal if they both have the same length and value. In Ruby, we can use the double equality sign == to check if two strings are equal or not. If they both have the same length and content, a boolean value True is returned. Otherwise, a Boolean value False is returned.

How do you compare numbers in Ruby?

In order to compare things Ruby has a bunch of comparison operators. The operator == returns true if both objects can be considered the same. For example 1 == 1 * 1 will return true , because the numbers on both sides represent the same value.

What is difference between EQL and equal in Ruby?

Ruby exposes several different methods for handling equality: a. equal?(b) # object identity - a and b refer to the same object a. eql?(b) # object equivalence - a and b have the same value a == b # object equivalence - a and b have the same value with type conversion.


1 Answers

Use a.equal? b

http://www.ruby-doc.org/core/classes/Object.html

Unlike ==, the equal? method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b) iff a is the same object as b).

like image 198
John Millikin Avatar answered Oct 06 '22 12:10

John Millikin