Given an array
array = ['a','b','c','d','e','f']
and a hash
hash = {"a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5,"f"=>6}
I would like to create a new array which contains the objects corresponding to the value of every index from the third onward. I am currently doing it like this:
newArray = []
array[2..-1].each do |item|
newArray << hash[item]
end
I feel like this could be done in one line (possibly without creating the newArray
beforehand as I would like to put this directly into another object's initialization code). Is this possible?
newArray = []; array[2..-1].each do |item| newArray << hash[item] end
Voilà: one line.