Project

General

Profile

Actions

Feature #6532

closed

More methods for Hash and Array: Hash#has_all_keys? and family, Array#delete_at for multiple arguments

Added by prijutme4ty (Ilya Vorontsov) about 13 years ago. Updated about 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:45384]

Description

I suggest introducing Hash methods: has_all_keys?, has_any_key?, has_none_key?, has_one_key?
to write: input.has_all_keys? %w{A C G T}
instead of: %w{A C G T}.all?{|letter| input.has_key? letter}

and to write args.has_one_key?(:input_file, :input_string, :input_from_another_source, ...) instead of obvious but verbose code with iterating through keys

Also I suggest reimplement method Array#delete_at to work with multiple keys:
def delete_at(*args)
args.sort.reverse{|index| current_version_of_delete_at index}
end

It helps not only writing multiple deletion code faster but also prevents mistakes with deleting elements from an array in arbitrary order

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0