Adding a new method to the Array class

instance, ruby

Solution

Use Ruby Open Classes:

class Array
  def mymethod
    #implementation
  end
end

Problem

I have a new requirement on Array object. So I need to add my own method to built-in Array class. How do I add a new method so that whatever Array object I create, it will also have my instance method?

Original source