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.
> But to be very percise it should probably be
> changed to match Array's. Consider that Array's = method does take
> multuiple parameters related to slicing. Facets' deals with that by
> allowing it to also take an Array parameter:
>
> a =
> a[[1,2,3]] = :a, :b, :c
> a #=> [ :a, :b, :c ]
>
> Hash's can be made to do the same. What do you think?
Actually, I don't like that solution very much. It doesn't seem very
elegant.
Yes, but sometime simplicity and elegance have to give way to
practicality. I do hope Matz will take some time to address the
"duckability" between Array and Hash for 2.0, though. That would
certainly go a long way toward simplicity and elegance more than
anything.
T.