Bug #2114: Array Hash inconsistency
http://redmine.ruby-lang.org/issues/show/2114

Author: Wim Yedema
Status: Open, Priority: Normal
Category: lib
ruby -v: ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

This is something I never really noticed until recently. There is some inconsistency between functions on Arrays and Hashes that requires you to repeat yourself needlessly if you want to be able to support both (breaking DRY):

function          | semantic                    | equivalent

Array.delete(x)   | delete elements ==x         | No equivalent in Hash
Hash.delete(x)    | delete element with key x   | Array.delete_at(x)
Array.each(&b)    | apply b to each value       | Hash.each_value(&b)
Hash.each(&b)     | apply b to each [key,value] | No equivalent in Array
Hash.each_key(&b) | apply b to each key         | Array.each_index(&b)

I realize this is not easy to change for some functions, but others can be simply added.


----------------------------------------
http://redmine.ruby-lang.org