Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- From: "Robert Klemme" <shortcutter@xxxxxxxxxxxxxx>
- Date: Thu, 11 Oct 2007 15:45:12 +0900
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
.
- Follow-Ups:
- Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- From: Rick DeNatale
- Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- References:
- will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- From: Peña, Botp
- Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- From: Peña, Botp
- Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- From: David A. Black
- Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- From: mortee
- will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- Prev by Date: Re: what does print call internally?
- Next by Date: Re: what does print call internally?
- Previous by thread: Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- Next by thread: Re: will #in? be in ruby2? (was Re: Finding shared elements between to arrays.)
- Index(es):
Relevant Pages
|