Add method to child class : child class « Class « Ruby






Add method to child class

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

class Cat < Pet
end

class Dog < Pet
  def bark
    puts "Woof!"
  end
end

 








Related examples in the same category

1.Add more accessors in child class
2.Check class attribute of child class
3.Add methods in subclass