Project

General

Profile

Feature #8811

Counterpart to `Hash#key?` for `Array`

Added by sawa (Tsuyoshi Sawada) almost 7 years ago. Updated over 6 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:56784]

Description

=begin
Hash hash key? to tell if a key exists without checking the value. It would be convenient if there were a counterpart in Array. Suppose it is called Array#index?. Then it should behave as follows:

[1, 2, 3].index?(2) # => true
[1, 2, 3].index?(3) # => false
[1, 2, 3].index?(-3) # => true
[1, 2, 3].index?(-4) # => false

This is useful when we want to insert/move/delete elements to/from a certain position of an array. Without checking if a value exists, it can be messed up. Implementing a check is cumbersome now. With the proposed method, it would become easy.

=end


Files

rb_ary_has_index.patch (2.08 KB) rb_ary_has_index.patch Simple implementation with test phluid61 (Matthew Kerwin), 08/27/2013 09:04 AM

Also available in: Atom PDF