Ruby Unique Feature – Open Classes

Open Classes

A class in ruby can be modified by adding method or variable at any point in the code.

Sample code as follow :

class ClassA
  def method1
   puts '1'
  end
end

var1 = ClassA.new
var1.method1

class ClassA
 def method2
 puts '2'
 end
end

var1.method2
var1.method1

 

Leave a Reply

Your email address will not be published. Required fields are marked *