Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Module#prepend

prepend(module, ...) → self

Invokes Module.prepend_features on each parameter in reverse order.

Ruby version changes

  1. 3.1
    • Module#prepend now modifies the ancestor chain if the receiver already includes the argument. Module#prepend still does not modify the ancestor chain if the receiver has already prepended the argument. [Bug #17423]

  2. 3.0
    • Module#include and Module#prepend now affect classes and modules that have already included or prepended the receiver, mirroring the behavior if the arguments were included in the receiver before the other modules and classes included or prepended the receiver. [Feature #9573]

      Example
      class C; end
      module M1; end
      module M2; end
      C.include M1
      M1.include M2
      p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]