Skip to content

Documentation


Documentation / @blazetrails/activesupport / prepend

Function: prepend() ​

prepend(target, mod): void

Defined in: packages/ruby-compat/dist/include.d.ts:695

Ruby-style prepend for mixing module methods into a class above it.

Ruby's prepend inserts the module ahead of the class in the ancestry, so a method the module defines wins over the same method in the class body — the one behavioural difference from include, which loses to it. Here that is a plain assignment onto the class prototype.

The method it replaces is seated under the module method's super slot, so the module reaches it with rbCallSuper, as Ruby's super does.

A module whose method table is already in the ancestry is skipped whole, the way include_modules_at skips one (vendor/ruby/v3.3.11/class.c:1281,1291,1296).

Mirrors: Ruby's Module#prepend — vendor/ruby/v3.3.11/eval.c:1196 rb_mod_prepend, backed by vendor/ruby/v3.3.11/class.c:1430 rb_prepend_module.

Parameters ​

ParameterType
targetAnyClass | ((...args) => object) | { prototype: object; }
modobject | AnyClass | Module<Record<never, never>>

Returns ​

void

No Rails Equivalent ​

PERMANENT — a Ruby core-language primitive, which Rails uses but does not define.