ruby 编写迭代器
class My def initialize(name,age) @name=name @age=age end def sayName puts @name end def sayAge puts @age end def repeat(num) while num>0 yield num-=1 end end end m=My.new("wanan", 23) m.repeat(3){puts "test"}
posted on 2013-07-03 10:33 Ijavascript 阅读(142) 评论(0) 编辑 收藏 举报