Check class attribute of child class : child class « Class « Ruby






Check class attribute of child class


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

class Cat < Pet
end

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


a_dog = Dog.new

puts a_dog.class

 








Related examples in the same category

1.Add more accessors in child class
2.Add method to child class
3.Add methods in subclass