Skip to content
instance method

Module#extend_object

(untyped arg0) -> untyped
extend_object(obj) → obj

Extends the specified object by adding this module’s constants and methods (which are added as singleton methods). This is the callback method used by Object#extend.

Example
module Picky
  def Picky.extend_object(o)
    if String === o
      puts "Can't add Picky to a String"
    else
      puts "Picky added to #{o.class}"
      super
    end
  end
end
(s = Array.new).extend Picky  # Call Object.extend
(s = "quick brown fox").extend Picky

produces:

Picky added to Array
Can't add Picky to a String
See also #extended #freeze #deprecate_constant #include also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0