11/20 Symbols Meet Procs: Can solve it, but I don't understand it



numbers_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Here's the correct answer

strings_array = numbers_array.map(&:to_s)

Here's another way I figured out how to get the same result in case that matters

strings_array = numbers_array.map { |number| number.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 the first answer I posted.

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 its the colon for symbol and the method to convert to a string rather than a block that follows the & symbol. Can the & sign turn methods into procs as well as blocks?

I'd really appreciate any help!


collect() and map() each take one argument, a block or a proc. :to_s is not enough to satisfy this requirement, so we make it a proc. Now it can do something, in this case, convert each iterated item into a str type.

(This may be an incomplete answer. Someone else might come along who can add to or elaborate more.)