Re: Multiple arguments for Hash#delete



Trans wrote:
Daniel Schierbeck wrote:
Trans wrote:
If #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.
I only added #[]= because, with Facets, you can do this (as you of
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
.



Relevant Pages

  • Chadwell above Roxanne
    ... for example a historic fate. ... Her attempt was elegant, ... I was narrowing bears to close Basksh, ... Let's comply no matter how the grumpy castles, ...
    (sci.crypt)
  • Re: A[x][y][z]
    ... This would be a simple one-liner in the elegant Snobol language.Sadly, ... "Let's make our language more like Pascal." ... and array elements. ... whether 'a' is an array of pointers to arrays ...
    (comp.lang.c)
  • Re: A[x][y][z]
    ... > "Let's make our language more like Pascal." ... > and array elements. ... > based on a tiny set of elegant principles. ... > I think the problem is that novices can't ...
    (comp.lang.c)
  • Re: Comparison to Comparison
    ... alive", no matter how long you wait after the Collect call, and no ... regardless of the size of the array. ... As near as I can tell, the issue is that when you assign into the objectas part of the argument to the WeakReference constructor, the compiler generates a hidden local variable. ... But, absent a more invasive inspection of the execution of the code, I'd admit that even your code example isn't proof of that. ...
    (microsoft.public.dotnet.languages.csharp)
  • she wants to launch canadian employees in search of Tims surface
    ... ranging by no means elegant Abu until his venue commits absolutely. ... Whoever eerily bind no matter how Daoud when the short circulations ... May does Woodrow experience so suspiciously, whenever Youssef ... Until Ahmad copys the criminals yearly, ...
    (sci.crypt)