Ruby - Class Override methods

Introduction

You can override your own methods.

Demo

class Dog 
  def talk #  w w  w. j a  va 2  s.c  om
    puts "Woof!" 
  end 
end 

my_dog = Dog.new 
my_dog.talk 

class Dog 
  def talk 
    puts "Howl!" 
  end 
end 

my_dog.talk

Result

Here, you created a basic class with a simple method, then reopened that class and redefined a method.

Related Topic