Module: RubyLLM::Toolbox::RubyOutline
- Defined in:
- lib/ruby_llm/toolbox/ruby_outline.rb
Overview
Extracts a structural outline (classes, modules, methods, constants) from Ruby source, with line numbers and nesting depth. Parsing only — the code is never executed.
Two backends sit behind one dispatcher and produce identical Entry lists:
* PrismBackend — used automatically when `require "prism"` succeeds.
Prism is bundled with Ruby 3.3+, so on a modern Ruby this needs no gem
install. It is the same parser the VM itself uses, so its line numbers
and structure are authoritative.
* RipperBackend — the stdlib fallback for runtimes that don't bundle
Prism (e.g. non-MRI). Dependency-free, always present.
Parity between the two is enforced by spec/ruby_outline_parity_spec.rb and by bin/verify_prism_parity, which can be run under any Ruby (e.g. a sandboxed ruby:3.4) to confirm the backends agree.
Defined Under Namespace
Modules: PrismBackend, RipperBackend Classes: Entry, ParseError
Class Method Summary collapse
- .active_backend ⇒ Object
-
.extract(source, backend: active_backend) ⇒ Object
Returns an Array<Entry> in source order.
-
.prism_available? ⇒ Boolean
True when the Prism backend can be loaded on this Ruby.
Class Method Details
.active_backend ⇒ Object
42 43 44 |
# File 'lib/ruby_llm/toolbox/ruby_outline.rb', line 42 def active_backend prism_available? ? PrismBackend : RipperBackend end |
.extract(source, backend: active_backend) ⇒ Object
Returns an Array<Entry> in source order. Raises ParseError on a syntax error. Pass backend: to force a specific one (used by the parity tests).
48 49 50 |
# File 'lib/ruby_llm/toolbox/ruby_outline.rb', line 48 def extract(source, backend: active_backend) backend.extract(source.to_s) end |
.prism_available? ⇒ Boolean
True when the Prism backend can be loaded on this Ruby. Memoized.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_llm/toolbox/ruby_outline.rb', line 31 def prism_available? return @prism_available if defined?(@prism_available) @prism_available = begin require "prism" true rescue LoadError false end end |