Array map with regular expression : map « Array « Ruby






Array map with regular expression


[1,2].map{|x| /#{x}/}   # => [/1/, /2/]
[1,2].map{|x| /#{x}/o}  # => [/1/, /1/]

 








Related examples in the same category

1.The map method returns a new array instead of a string.
2.Change array elements with map!
3.Map to uppercase