Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

module_function without arguments is not applied to subsequent method definitions

Aperta
#1,823 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
documentation

Direzione di ricerca

Inizia generando la documentazione per l'esempio in lib/json/common.rb, quindi segui la gestione di Module#module_function da parte di RDoc e il relativo percorso esistente per gli argomenti espliciti. Verifica come vengono elaborati i nodi def successivi alla forma senza argomenti. Il lavoro è completato quando i metodi successivi compaiono come metodi di istanza privati e metodi di modulo pubblici, con una copertura di regressione per questo comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

RDoc 8 appears not to handle correctly the no-argument form of Module#module_function.

In Ruby, this:

module M
  module_function

  def foo
  end
end

defines both:

  • M.foo, as a public singleton method;
  • M#foo, as a private instance method.

However, RDoc appears to document foo only as an instance method and does not create/document the corresponding module method M.foo.

After generating the documentation, I would expect M.foo to appear as a module method.

It does not.

Real-world example

This occurs in json 3.0.2.

In lib/json/common.rb, JSON.parse is defined using the no-argument form of module_function:

module JSON
  # ...

  module_function

  # ...

  def parse(source, on_load: nil, object_class: nil, array_class: nil, **options)
    # ...
  end
end

Ruby therefore exposes this method as:

JSON.parse(...)

but RDoc 8 does not appear to document JSON.parse.

Likely cause

RDoc already seems to handle the explicit form:

module_function :foo

by converting an existing method to a module function.

The no-argument form has different semantics: it changes the state of the module so that methods defined subsequently become module functions.

RDoc therefore needs to remember that module_function was called without arguments and apply that state to later def nodes, until the relevant scope ends or the state is otherwise changed.

Conceptually:

module_function

def foo
end

should result in RDoc recording both:

# private instance method
M#foo

# public singleton/module method
M.foo
Notes

This does not appear to be a Prism parsing issue itself: the syntax is parsed normally. The missing part seems to be in RDoc's tracking of the semantic state introduced by a no-argument module_function.

I encountered this while generating documentation for json 3.0.2 with RDoc 8.

Lingua principale
Ruby
Stelle
929
Fork
469
Merge medio
2g 3h
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/rdoc

Tutte le issue di ruby/rdoc

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.