To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

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编辑  收藏  举报