On 6/20/06, Matthew Smillie <M.B.Smillie@sms.ed.ac.uk> wrote:
On Jun 20, 2006, at 15:17, James Edward Gray II wrote:
> a = [ { :foo => :bar }, { :foo => :bar } ]
>
> p a #=> [{:foo=>:bar}, {:foo=>:bar}]
> p a[0] == a[1] #=> true
> # why does this next call do nothing?
> p a.uniq #=> [{:foo=>:bar}, {:foo=>:bar}]
Seems to compare on object id, rather than with ==. I couldn't
speculate on any more significant answer to 'why?'
From: James Edward Gray II [mailto:james@grayproductions.net]
Sent: Tuesday, June 20, 2006 4:32 PM
> p a.uniq #=> [{:foo=>:bar}]
So which one is uniq() really using? eql?()?
James Edward Gray II
both, uniq creates a hash from the array.
Iterating over the array it deletes from the hash and removes
values from the array if there is no such element in the hash
left. To find the element in the hash both methods are necessary.
To unsubscribe ML <ruby-talk@ruby-lang.org>, send "unsubscribe" in the mail body
to the address <ruby-talk-ctl@ruby-lang.org>. Also you can send "# unsubscribe".
"#" is prepended in fml documents for some historically reasons. "#"
is NOT NEEDED in almost all cases but fml can accepct commands with or
without '#'. Please ignore this in default configuration.
···
On Jun 20, 2006, at 10:29 AM, Hamid Rasoulian wrote:
Can any body help me with How to "unsubscribe" from the ruby talk
mailing list.
There's also Hash#default and Hash#default_proc to take in mind.
And you can't rely on Proc#hash and friends...
Otherwise, it's trivially implementable.
···
On Tue, Jun 20, 2006 at 11:56:21PM +0900, James Edward Gray II wrote:
>>So which one is uniq() really using? eql?()?
>
>both, uniq creates a hash from the array.
OK, let me expand my question slightly: why are hash() and eql?()
not meaningfully defined for Hash?
Doesn't Array.hash just aggregate the hash() of its elements? Why
could Hash not do the same?