我需要将fixnums转换为字符串.我的解决方案是:
arr.map {|a| a.to_s}
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
Way*_*rad 33
arr.map(&:to_s)
Run Code Online (Sandbox Code Playgroud)
这使用Ruby> = 1.8.7中的一个漂亮的新功能,即"符号到proc"的快捷方式,并且等同于您问题中的代码.
| 归档时间: |
|
| 查看次数: |
12313 次 |
| 最近记录: |