Extends class : inheritance « Class « Ruby






Extends class


class Hello
  def howdy
    greeting = "Hello, Matz!"
    puts greeting
  end
end

class Goodbye < Hello
  def solong
    farewell = "Goodbye, Matz."
    puts farewell
  end
end

friendly = Goodbye.new
friendly.howdy
friendly.solong

 








Related examples in the same category

1.Basing one class on another is called inheritance.
2.how inheritance works in code form
3.Basing One Class on Another: a Demo
4.different types of people
5.Structuring Your Pets Logically
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