ror

>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

公告

搜索

 
 

常用链接

我的标签

随笔分类

随笔档案

文章分类

friend blog

    最新评论

    阅读排行榜

    评论排行榜

    arr = "1,2,3".split(',')
    arr.map!{
    |item| item = item.to_i} #一般可以用map!方法来改变原数组内容
    0.upto(arr.length-1){|idx|arr[idx] = arr[idx].to_s} #再将数组内容改回字符串形式 使用upto方法


    fixnum对象的upto和downto方法,可以很方便的作为访问一个数组的索引。

    其实也可以这样做
    (0..arr.length-1).each{|n| arr[n] = arr[n].to_i}


    总之ruby是想怎么写就怎么写 非常方便   
    原文地址:https://www.cnblogs.com/lexus/p/1864583.html