| name | ruby-prism |
| description | Analyze Ruby files using the Prism AST parser. Use when exploring unfamiliar Ruby files, understanding class/module structure, analyzing method signatures, or getting a file overview before making changes. Extracts outlines, method bodies, inheritance, mixins, and Rails patterns (associations, validations, callbacks, scopes).
|
Ruby Prism Analyzer
Analyze Ruby files using the Prism gem for AST parsing. Provides structural analysis
without executing Ruby code.
Usage
Run scripts/prism with these options:
<path-to-ruby-prism-skill>/scripts/prism --outline path/to/file.rb
<path-to-ruby-prism-skill>/scripts/prism --outline path/to/file.rb path/to/other.rb
<path-to-ruby-prism-skill>/scripts/prism --method method_name path/to/file.rb [path/to/other.rb ...]
<path-to-ruby-prism-skill>/scripts/prism --relationships path/to/file.rb [path/to/other.rb ...]
Output
Outline (--outline)
Shows:
- Classes with superclass and line ranges
- Modules with line ranges
- Constants with locations
- Attributes (
attr_reader, attr_writer, attr_accessor) with visibility
- Methods with parameters, visibility, and line ranges
- Instance/class variables
- Dependencies (
require, require_relative)
- Rails patterns (associations, validations, callbacks, scopes)
- Exception handling blocks
- Inheritance and mixin relationships
Method Body (--method)
Extracts the complete source of a method including line numbers.
Relationships (--relationships)
Shows:
- Inheritance:
Child < Parent
- Includes:
Class includes Module
- Extends:
Class extends Module
Example Output
User < ApplicationRecord [1-45]
includes Searchable
@name (rw) [2]
has_many :posts
validates :email
before_save :normalize_name
#full_name [10-12]
#validate_email- [30-35]
Sigils: # instance method, . class method, :: constant, @ attribute, ~ protected, - private