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