The two lines in this code:
p ["9", "6", "4"]
p %w(9 6 4)
return exactly the same array ["9", "6", "4"]
. But the first line with map
:
p ["9", "6", "4"].map(&:to_i)
works fine, and the second one:
p %w(9 6 4).map{&:to_i}
gives:
syntax error, unexpected &
p %w(9 6 4).map{&:to_i}
I also tried to wrap it in bracers (%w(9 6 4)).map(&:to_i)
, but had no luck. What is the problem with this code? %w(...)
is a shortcut for array of strings. Why is it not working in the same way?
UPD
Ok, I got it. That's a stupid question, but I can't delete this question, since it has answers already. I voted to close it..