Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)



2007/10/10, mortee <mortee.lists@xxxxxxxxxxxx>:
David A. Black wrote:
Hi --

On Wed, 10 Oct 2007, mortee wrote:
Why don't you just define #in? in Object yourself, and then you can use
it anywhere in your code. That's something I really like about Ruby: if
I'm missing something from a core or library class, I can just drop it
in for my own use.

It's not risk-free, though, since if two people define a given method
differently, one of them will get trampled on.

Yeah, that's what the other thread "Open-Closed..." is about in part:
method name collisions whithin a module/class coming from different sources.

I think that this problem should be solved somehow instead of avoiding
the power of ability to extend arbitrary classes. I'm absolutely aware
of the issue though.

While reading this thread another possible solution came to my mind:
what about an operator like "def_once" or "def!" which will raise an
exception if the method is defined for that class already? Of course,
we could cook our own using define_method but there are some
restrictions so it's not exactly equivalent to def.

Semantics would have to be carefully chosen. At the moment it seems
that "def_once" should raise only if a) the instance's class has an
instance method of the same name already or b) there is a singleton
method of the same name. However, I am not sure how to deal with the
situation when there is an instance method in the class and then a
singleton method definition is attempted.

What do you guys think? This would at least make sure that you
immediately notice if a method is defined twice and it seems to easier
integrate with the language than selector namespaces.

Kind regards

robert

.



Relevant Pages

  • Adding event handlers dynamically
    ... Maybe I'm missing something obvious, but is there some way to call ... Delegate) but create the delegate ... dynamically, but from an instance method, not a static one ... have a ctor. ...
    (microsoft.public.dotnet.framework)
  • Re: Array.Sort?
    ... Can't really think of a good reason. ... Unless there is something I'm missing as well. ... > Is it because it's changing the array you're sorting? ... > limitation where if it was an instance method, ...
    (microsoft.public.dotnet.framework)
  • Re: Array.Sort?
    ... Unless there is something I'm missing as ... I would imagine that concurrency is the issue. ... sort via an instance method in a thread. ...
    (microsoft.public.dotnet.framework)