Project

General

Profile

Actions

Feature #13118

closed

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

Added by crb002 (Chad Brewbaker) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
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) over 5 years ago

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) over 5 years ago

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

Updated by shyouhei (Shyouhei Urabe) over 5 years ago

  • Status changed from Open to Closed

No problem. Thank you anyway.

Actions

Also available in: Atom PDF