I'm new to ruby and i want to print the last element in a sub array from a 2d array. I've tried using an each iterator but it gave me an error: "no implicit conversion of Array into Integer (TypeError)"
pairs = [['name', 'sam'], ['age', '56'], ['height', '179']]
pairs.each{ |x| puts pairs[x][1] }
Preferred output:
sam
56
179
Any suggestions will be appreciated! Thanks.
eachblock,xrefers to a single sub-array at a time, e.g. for the first iteration you can think ofx = ['name', 'sam']. Does that help?