Re: Multiple arguments for Hash#delete
- From: Daniel Schierbeck <daniel.schierbeck@xxxxxxxxx>
- Date: Fri, 18 Aug 2006 00:23:02 +0200
Trans wrote:
Daniel Schierbeck wrote:Trans wrote:I only added #[]= because, with Facets, you can do this (as you ofIf #delete should be altered, why should #[] and #[]= ?You may have a point. Though it doesn't matter as much becuase it's
much less often the anyone depends on the return value of []=. ie. we
just use it to set values.
course know)
hsh[:a, :b, :c] = 1, 2, 3
which matches nicely with
a, b, c = hsh[:a, :b, :c]
My point is that #delete is also a retrieval method, in the sense that
it returns the value it has removed from the hash. Therefore it is
natural for it to have the same functionality as #[], which in turn
means that we have to alter #delete in Facets.
a, b, c = hsh.delete(:a, :b, :c)
Simple and elegant.
Yea, I know what you mean. Believe me I went through the same viewpoint
when working on this for Array. Unfortunately the simplicity and
elegance start to crumble when:
a = hsh.delete(*array)
Which leads to things like:
a = [hsh.delete(*array)].flatten
or
a = hsh.delete(*array)
case a
when Array
...
else
...
end
Which means you'll just opt to use #delete_at anyway.
Of course you will. In this case, #delete_at fits perfectly well with the intended usage. I just don't see the problem with using #delete_at in such a case, and #delete in cases where you have a known number of keys.
I propose Facets have *both* an altered #delete *and* a #delete_at method.
Cheers,
Daniel
.
- References:
- [Facets] Multiple arguments for Hash#delete
- From: Daniel Schierbeck
- Re: [Facets] Multiple arguments for Hash#delete
- From: nobu
- Re: [Facets] Multiple arguments for Hash#delete
- From: Daniel Schierbeck
- Re: Multiple arguments for Hash#delete
- From: Trans
- Re: Multiple arguments for Hash#delete
- From: Daniel Schierbeck
- Re: Multiple arguments for Hash#delete
- From: Trans
- Re: Multiple arguments for Hash#delete
- From: Daniel Schierbeck
- Re: Multiple arguments for Hash#delete
- From: Trans
- Re: Multiple arguments for Hash#delete
- From: Daniel Schierbeck
- Re: Multiple arguments for Hash#delete
- From: Trans
- [Facets] Multiple arguments for Hash#delete
- Prev by Date: Re: reading website
- Next by Date: Re: Perl Junkie: Bad form?
- Previous by thread: Re: Multiple arguments for Hash#delete
- Next by thread: Re: [Facets] Multiple arguments for Hash#delete
- Index(es):
Relevant Pages
|