Structuring Your Pets Logically : inheritance « Class « Ruby






Structuring Your Pets Logically


class Pet
  attr_accessor :name, :age, :gender, :color
end

class Cat < Pet
end

class Dog < Pet
end

class Snake < Pet
end

 








Related examples in the same category

1.Basing one class on another is called inheritance.
2.Extends class
3.how inheritance works in code form
4.Basing One Class on Another: a Demo
5.different types of people
6.If the class Name were in a different file, you would just require that file first
7.Add new constructor
8.Module and class hierarchy
9.Subclass Array class