Project

General

Profile

Actions

Feature #13118

closed

Array#at(*indexes); Array#at([indexes])

Feature #13118: Array#at(*indexes); Array#at([indexes])

Added by crb002 (Chad Brewbaker) almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:79036]

Description

It is useful to have Array return a repeated permutation. Rather than add another method, we could overload Array#at to take multiple indexes.

a = [ "a", "b", "c", "d", "e" ] a.at(0) #=> "a" a.at(-1) #=> "e" #New stuff a.at(0,1) #=> ["a", "b"] a.at(0,0) #=> ["a", "a") a.at([2,3]) #=> ["c", "d"] a.at([-1,1]) #=> ["e", "b"] 

Updated by jeremyevans0 (Jeremy Evans) almost 9 years ago Actions #1 [ruby-core:79037]

Array#values_at already exists for this purpose:

a.values_at(0,1) #=> ["a", "b"] a.values_at(0,0) #=> ["a", "a") a.values_at(*[2,3]) #=> ["c", "d"] a.values_at(*[-1,1]) #=> ["e", "b"] 

Updated by crb002 (Chad Brewbaker) almost 9 years ago Actions #2 [ruby-core:79040]

Well, I am an idiot. Read through the array spec twice and missed it both times. Please close.

Updated by shyouhei (Shyouhei Urabe) almost 9 years ago Actions #3 [ruby-core:79042]

  • Status changed from Open to Closed

No problem. Thank you anyway.

Actions

Also available in: PDF Atom