array.equal? - RUBY
This is a discussion on array.equal? - RUBY ; Sebastian Hungerecker wrote:
> Nick Bhanji wrote:
>> You gotta chill,
>
> I am chilled. My "wtf" was an expression of confusion, not anger or
> "riled
> up-ness".
We're cool -- have a wonderful day
--
Posted via ...
-
Re: array.equal?
Sebastian Hungerecker wrote:
> Nick Bhanji wrote:
>> You gotta chill,
>
> I am chilled. My "wtf" was an expression of confusion, not anger or
> "riled
> up-ness".
We're cool -- have a wonderful day
--
Posted via http://www.ruby-forum.com/.
-
Re: array.equal?
Nick Bhanji wrote:
> Hello All,
>
> I am not sure where to ask this, but someone after reading this can tell
> me more.
>
> I am trying to right a functions where I am comparing 2 arrays. Here is
> an example.
>
> a = [1,1]
> b = [1,1]
>
> in the irb, I executed a.equal? b and the result came as false.
>
> here is the output:
> irb(main):031:0> a =[1,1]
> => [1, 1]
> irb(main):032:0> b =[1,1]
> => [1, 1]
> irb(main):033:0> a.equal? b
> => false
> irb(main):034:0>
>
> however when I execute a.eql? b the result is true.
>
> My questions:
> 1. why is equal? listed in the methods for the array
> 2. what is the definition of equal? in the case of array?
> 3. why is there another function eql? performing the actual equal test
>
> I am using ruby version 1.8.6 for the windows
>
> Thank you in advance.
>
> Nick.B
The equal? method comes from the Object class. The equal? method will
return true if and only if the two objects are the same object. The two
lists are two independently created lists, so this will be false. The
eql? method is an alias for this method.
If you want to see if two arrays contain the same objects, use the ==
operator.
a = [1,1]
b = [1,1]
print "yes" if a == b
-
Re: array.equal?
Michael Morin wrote:
> The eql? method is an alias for [equal?].
Not on Array, it's not. Array#eql? behaves like Array#==, not like
Object#equal?.
--
NP: Depeche Mode - Lilian
Jabber: sepp2k@jabber.org
ICQ: 205544826
-
Re: array.equal?
2008/11/7 Sebastian Hungerecker <sepp2k@googlemail.com>:
> Michael Morin wrote:
>> The eql? method is an alias for [equal?].
>
> Not on Array, it's not. Array#eql? behaves like Array#==, not like
> Object#equal?.
The statement isn't true even in the _general case_: eql? and ==
implement the mathematical concept of "equivalence" and have usually
the same semantics (there are some noteworthy differences for
numbers). eql? being the more important method as it is also used by
Hash and others to find equivalent entires. equal? on the contrary
implements the concept of "identity". The default behavior of this in
class Object should never be overridden - but then again, the method
is used so sparingly that it probably won't matter. :-)
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end