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.
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.
Cheers,
Daniel