I'm working my way through Ruby's Codecademy course and I'm up to here https://www.codecademy.com/en/courses/ruby-beginner-en-L3ZCI/1/6?curriculum_id=5059f8619189a5000201fbcb#
The correct code (that I don't understand) to convert the array of numbers into an array of strings is posted below.
numbers_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
strings_array = numbers_array.map(&:to_s)
I've been looking through the forums and googling and at this point I'm still confused what the heck is going on in this code.
I'm confused by :to_s
because to_s
means to convert to strings and :
stands for symbols. Does :to_s
convert stuff into symbols or strings?
I'm confused by &
too. I get that the &
sign makes the block that follows it into a proc, but here it's the colon for symbol and the method to convert to a string rather than a block that follows the &
symbol.
I'd really appreciate any help!