level 2
rices=1
64.times {|square| puts " the
#{square} times,there are #
{rices} on the square";rices *=2}
问一下,为什么rices要事先定义,而那个square不用啊,感觉square默认值就是1
2014年07月27日 16点07分
1
level 6
继续看下去吧,square是代码块的参数,而且默认值也不是1
2014年07月28日 12点07分
2
level 3
基本知识先学完再敲代码,除非你有其他语言的基础。ruby是动态类型语言,变量不需要声明但使用前要先初始化(或曰赋值),rices不赋值怎么*=2啊?64.times是对象64调用其无参方法times()返回的一个迭代器,等价于: for square in 0...64 do puts"..."; rices*=2; end
2014年08月05日 10点08分
4