摘要: 1、ruby中的实例方法和Java等其他语言的定义类似class Dog def run puts "I'm running!" endend dog = Dog.new dog.run #I'm running!2、类方法定义时需要在方法名前加入类名称或者self关键字class Dog def Dog.species #或者 def self.species puts "I belong to the canine" endendDog.species #I belong to the canine注意:在ruby中类方法只能被类对象 阅读全文
posted @ 2013-11-21 21:25 yaocanwei 阅读(1062) 评论(2) 推荐(0) 编辑