hoc-methods
Conventions for class method definitions and their signatures. Use when defining, calling or reviewing a method. Method names belong to the naming convention…
от openreachtech★ 17 звёзд на GitHub
Установить hoc-methods в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Classes: Members / Methods
This summarizes conventions related to class method definitions.
Arguments should be a single named-argument object
- With some exceptions, the arguments of a defined method should in principle be received as a single object, using named arguments (destructuring assignment).
- Break each argument onto its own line and chop it down (one property per line).
// NG: positional arguments
generate (length) {
// ...
}
// OK: single named-argument object, chopped down
generate ({
length,
}) {
// ...
}
Exception: binding (inflator) methods pass arguments flat
- An inflator method — a static method that binds a value to the class and returns a derived
subclass, such as
.use()/.of()/.to()— is the exception to the rule above. What it receives instead, the exceptions to that, and its naming belong to/hoc-classes-inflators.
Do not pass properties directly to private methods
- Unless there is a specific reason, do not pass an (instance) property directly as an argument to a private / internal method.
- Internal methods should reference the properties they need directly from
this. This avoids passing arguments around and preserves encapsulation. - If a piece of logic needs a property passed as an argument, that is a sign that "it should be a static method rather than an instance method."
- However, making it static would remove the point of instantiation, so the correct approach is for instance methods to reference
thiswith no arguments.
// NG: passing your own property into an internal method
buildKey () {
return this.formatName({
name: this.name,
})
}
// OK: the internal method references `this` directly
buildKey () {
return this.formatName()
}
formatName () {
return this.name.toUpperCase()
}
A method that extracts resolves the value; it does not interpret it
Where a method's job is to take a value out of something — a config, a payload, a
response — it returns what is there, and null where nothing is. What absence means is
the caller's to decide, and deciding it inside the extractor hides the decision in the one
member whose name promises not to make any.
// NG: the extractor decides that no cap means an unreachable one
static extractMaxDocumentDepth ({
config,
}) {
return config.maxDocumentDepth
?? Infinity
}
// OK: it resolves, and leaves the meaning to whoever asked
static extractMaxDocumentDepth ({
config: {
maxDocumentDepth = null,
},
}) {
return maxDocumentDepth
}
- A default at the destructuring point is not interpretation.
= nullstates that an absent key and an explicitnullarrive the same way;?? Infinitystates what absence is worth, which is a different claim. - The caller skips the work rather than being handed a value that stands in for nothing. Where the value is absent, the member that would have used it returns early, and the behaviour that depends on it does not run.
// The consumer decides what an absent cap means
exceedsMaxDocumentDepth ({
depth,
}) {
if (!this.maxDocumentDepth) {
return false
}
return depth > this.maxDocumentDepth
}
- Two members then each hold one thing: the extractor holds where the value comes from, and the consumer holds what its absence does. A substitute value inside the extractor merges the two, and the merged version reads as though no decision had been made.
A recursion sits behind an entry point of its own
- How a recursion is laid out — the plain-named entry point, the
deep~member behind it, and where the accumulator's initial value is written — belongs to/hoc-methods-recursion. - Both members are methods, so everything on this page holds for them in full. The entry
point and the
deep~member each take a single named-argument object, the accumulator included.
Factory methods must be defined without exception
- Class definitions must define a factory method without exception.
- Unless a class is inheriting, every class definition must define
static create (...). (When inheriting, the parent class'screateis inherited, so it doesn't need to be redefined.) - The parameters of
static create (...)should define what is needed to construct the arguments passed to the constructor. - Factory methods should, unless there is a specific reason not to, be implemented as static methods
(
static create (...)).
Division of responsibility between the constructor and static create (...)
- What the constructor decides, and what it leaves to the factory methods, belong to
/hoc-classes-constructor. It is read here for the two things that land instatic create (...): a value the caller did not supply gets its default here, and where the constructor's parameter list divides what goes up to the base from what the class keeps, the factory method's parameter list repeats that division.
Varia
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/create-async.md
- references/instantiation.md
FAQ
Что делает скилл hoc-methods?
Conventions for class method definitions and their signatures. Use when defining, calling or reviewing a method. Method names belong to the naming convention; what the body is written with, to the statements convention; how a factory method builds a dependency, to the dependency-wiring convention; how a recursion is laid out, to the method recursion convention.
Как установить скилл hoc-methods?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hoc-methods запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…