Add methods in subclass : child class « Class « Ruby






Add methods in subclass


#!/usr/bin/env ruby

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

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

friendly = Goodbye.new
friendly.howdy
friendly.solong

 








Related examples in the same category

1.Add more accessors in child class
2.Add method to child class
3.Check class attribute of child class