補充

換種類別方法定義的方式來看更複雜一點的例子

12345678910111213141516171819202122232425262728293031

classAnimalclass<<self@@move=true@@breath="Air"@food=%w(meat grass)defdescriptionif@@moveputs"We Can beathe #{@@breath}"endenddeffood@food||=[]enddeffood_list@food.eachdo|food|puts"We like #{food}"endif@foodendendendAnimal.description# We Can beathe Air# nilAnimal.food_list# nilAnimal.food<<"meat"Animal.food_list# We like meat