Constructing a basic address book in Ruby. I have the following line of code in my program that iterates over the existing array(@address_book) based on a standard numeric input (entrynumber) to match the array index. The resulting value that matches that index is then returned. Here's the code in question:
puts @address_book.entries.each_with_index.select {|val, i| i == (entrynumber - 1)}
the results look great except that the index is also returned at the bottom, like this: (note 0 at the end of return) I'd ideally like the index number itself at the bottom not returned.
View by Entry Number
Entry Number: 1
You picked 1
Name: adam adams
Phone Number: 111-111-1111
Email: [email protected]
0
What am I missing in terms of returning the value, but without the index?
@address_book.entries[entrynumber-1]?