Documentation / @blazetrails/activesupport / extend
Function: extend()
extend<
T,M>(klass, ...argv):T&ExtendedAll<M>
Defined in: packages/ruby-compat/dist/include.d.ts:740
Ruby-style extend for mixing module methods onto a class as static methods.
In Ruby, extend SomeModule copies the module's methods onto the object itself (not its prototype). When used on a class, this makes the methods available as class-level (static) methods.
Precedence follows Ruby's singleton ancestry, the way include()'s does on the instance side: include SomeModule puts SomeModule::ClassMethods BELOW the class body (concern.rb:135-138), so a class-body static wins over the module's member of that name, while a later extend() wins over an earlier one. Accessor halves are resolved independently, since Ruby reads a getter (key) and a setter (key=) as two methods where TypeScript shares one property name between them. The name a class is born with, declared or an expression, is not a method its body defines: it stands for Module#name, which a module method on the singleton class is found before, so a module's name replaces it. A born name is the non-writable one; a static name field or accessor the class body declares is not, and wins.
Mirrors: Ruby's Object#extend — vendor/ruby/v3.3.11/eval.c:1778 rb_obj_extend, which returns the receiver (:1800). rb_extend_object (:1713-1716) is rb_include_module on the receiver's singleton class, so the module's ancestors come with it: a plain-object module's prototype chain is walked, nearest first, as include() walks it.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends object | AnyClass | - |
M extends object | AnyClass | Module<Record<never, never>> | object | AnyClass | Module<Record<never, never>> |
Parameters
| Parameter | Type |
|---|---|
klass | T |
...argv | M[] |
Returns
T & ExtendedAll<M>
No Rails Equivalent
PERMANENT — a Ruby core-language primitive, which Rails uses but does not define.
Usage: extend(Base, ConnectionHandlingMethods); // Now Base.connectedTo(...) works