From: Caleb Clausen on
On 6/11/10, Robert Dober <robert.dober(a)gmail.com> wrote:
> OP wanted to use Array#&, and Array#&, for a reason not too clear to
> me, uses Object#eql? instead of Object#== I did discourage the
> overloading of Object#eql? and Object#hash for *that purpose*.

Array#& uses eql? instead of == because internally, it works something
like this:

class Array
def &(other)
h1={}
other.each{|x| h1[x]=true}
select{|x| h1[x] }
end
end

In other words, it creates a (hash) index to get a speedup. (From
O(M*N) to O(M+N).)

From: Robert Dober on
On Fri, Jun 11, 2010 at 9:11 PM, Caleb Clausen <vikkous(a)gmail.com> wrote:
I see, thanx :)

From: Robert Klemme on
On 06/11/2010 08:15 PM, Robert Dober wrote:
> On Fri, Jun 11, 2010 at 6:47 PM, Robert Klemme
> <shortcutter(a)googlemail.com> wrote:
>> On 10.06.2010 18:27, Robert Dober wrote:
>>> On Thu, Jun 10, 2010 at 6:10 PM, Robert Klemme
>>> <shortcutter(a)googlemail.com> wrote:
>>>
>>>> http://blog.rubybestpractices.com/posts/rklemme/018-Complete_Class.html
>>>>
>>>> http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html
>>> I
>>> You define #eql? and #hash for your convenience. So good, so bad. My
>>> question simply was: Show my why *not* redefining #hash and #eql? will
>>> cause problems, because that was Wilson's statement. I am still
>>> waiting :(.
>> The advice to implement #eql? and #hash really only makes sense if
>> equivalence can reasonably be defined for a class and if instances of that
>> class should be used as Hash keys or in Set. If not at least equivalence
>> can be defined other than via identity (which is the default) then it is
>> perfectly reasonable to not override both methods and go with the default
>> implementation.
> But that was *exactly* my point.

I don't think we disagree, nor do I argue with you. I just posted blog
links as illustration to Rein's point about how to implement those methods.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
From: Robert Dober on
On Sat, Jun 12, 2010 at 10:55 AM, Robert Klemme
<shortcutter(a)googlemail.com> wrote:

> I don't think we disagree, nor do I argue with you.  I just posted blog
> links as illustration to Rein's point about how to implement those methods.

Forgive my confusion then.
Cheers
Robert

--
The best way to predict the future is to invent it.
-- Alan Kay

From: Robert Klemme on
On 12.06.2010 11:01, Robert Dober wrote:
> On Sat, Jun 12, 2010 at 10:55 AM, Robert Klemme
> <shortcutter(a)googlemail.com> wrote:
>
>> I don't think we disagree, nor do I argue with you. I just posted blog
>> links as illustration to Rein's point about how to implement those methods.
>
> Forgive my confusion then.

No problem. I think I fueled it by not including a comment in the
original posting. Sorry for that.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/