From: takashikkbn@... Date: 2017-06-29T01:07:45+00:00 Subject: [ruby-core:81821] [Ruby trunk Feature#13692] Array#index? Issue #13692 has been updated by k0kubun (Takashi Kokubun). ~~~ ruby def from(index) if index?(index) self[index..-1] else [] end end ~~~ Not considered well, but wouldn't it be sufficient to use following simple implementation? ~~~ ruby def from(index) self[index..-1] || [] end ~~~ And first of all, I couldn't imagine the use case to use such Array#from with large negative index too. ---------------------------------------- Feature #13692: Array#index? https://bugs.ruby-lang.org/issues/13692#change-65516 * Author: se8 (S��bastien Durand) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hello! We currently have these methods: ~~~ Hash#key(value) Hash#key?(key) Array#index(value) ~~~ I was thinking we could add this tiny method: ~~~ Array#index?(index) ~~~ as this is sometimes useful to check if an array index exists. ~~~ ruby class Array def index?(index) index.between?(0 - size, size - 1) end end ['a', 'b', 'c'].index?(0) # => true ['a', 'b', 'c'].index?(2) # => true ['a', 'b', 'c'].index?(3) # => false ['a', 'b', 'c'].index?(-1) # => true ['a', 'b', 'c'].index?(-3) # => true ['a', 'b', 'c'].index?(-4) # => false [false, nil].index?(0) #=> true [false, nil].index?(1) #=> true ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: