Ruby - Extend Ruby's standard classes with partial class

Introduction

You can use partial class definitions to add features to Ruby's standard classes such as Array:

Demo

class Array 
   def myMethod # ww w .j  av a 2  s . c om
      puts( "myMethod" ) 
   end 
end 

[1,2,3].myMethod

Result

This adds the myMethod method to the Array class so that the code above can now be executed

Related Topic