开发者

Using Ruby, how do I convert all array values to a given type?

I ne开发者_如何学Goed to convert fixnums to strings. My solution is:

arr.map {|a| a.to_s}

Is there a better way?


arr.map(&:to_s)

This uses a spiffy new feature in Ruby >= 1.8.7, the "symbol to proc" shortcut, and is equivalent to the code in your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜