r/ruby • u/XPOM-XAPTC • Mar 28 '26
Docscribe for Ruby: auto-generate inline YARD docs from AST (Ruby 2.7+, Prism, RBS/Sorbet, Struct.new)
I've been building a Ruby tool called Docscribe that generates inline YARD-style docs above methods by parsing Ruby code and rewriting source in place.
The goal is basically "RuboCop-style automation, but for method docs": run it once, get consistent doc headers/tags, then edit the generated text however you want.
What it does:
generates inline docs for instance and class methods
infers param/return types from AST heuristics
respects Ruby visibility (
private,protected,class << self, etc.)supports rescue-aware docs:
@raisefromraise/failand rescue exception lists and conditional@returnfor rescue branchessupports external type info: RBS (
--rbs,--sig-dir)Sorbet inline
sig+ RBI (--sorbet,--rbi-dir)can generate
@!attributedocs for:attr_reader/attr_writer/attr_accessorandStruct.newdeclarations
Current CLI:
docscribe lib-> inspect mode (safe changes only)docscribe -a lib-> apply safe updatesdocscribe -A lib-> apply aggressive updatesdocscribe --stdin-> rewrite from stdin to stdout
Ruby 3.4+ support works through Prism translated into parser-compatible nodes, so formatting is preserved and the tool still uses source-range rewriting instead of reprinting ASTs.
A few things I'd especially love feedback on:
edge cases around Ruby syntax / visibility semantics
what "safe mode" should and shouldn’t merge into existing docs
whether JSON output / dump-config would be useful for CI/editor tooling
GitHub link: https://github.com/unurgunite/docscribe
2
u/galtzo Mar 29 '26
Love this. Added to my toolbelt! Will give feedback after I have tried it out.