Ruby
Dynamic Regex since v1.0๐ด Tracks public/private visibility as it scans. Methods before a private marker are public. initialize excluded.
.rb What gets detected
The public surface spec-sync tracks for Ruby.
- class and module declarations (always public at namespace level)
- Top-level def (zero indentation, no _ prefix)
- Indented def (respects private/protected visibility markers)
- Constants (UPPERCASE_NAME = ...)
- attr_accessor / attr_reader / attr_writer symbols
Detection rules
Class and module declarations
class and module names starting with an uppercase letter are always captured as public namespace-level exports.
module Authentication
class AuthService
end
end
class _InternalHelper # still captured: class names start with uppercase Visibility-tracked methods
Methods after a bare private or protected keyword are excluded. Methods before, or after a bare public keyword, are included. initialize is always excluded.
class Foo
def public_one; end # included
def public_two; end # included
private
def secret_one; end # excluded
public
def public_again; end # included
protected
def also_hidden; end # excluded
end Constants
Any uppercase-only constant assignment (NAME = value) is captured.
DEFAULT_TTL = 3600
API_VERSION = '1.0' attr_accessor / attr_reader / attr_writer
Attribute declarations extract the symbol names as separate exports.
attr_reader :token, :expires_at
attr_accessor :name, :email Example: spec & source
The *.spec.md contract on the left,
the Ruby source it documents on the right. spec-sync matches the two.
Spec (*.spec.md)
---
module: auth
version: 1
status: stable
files:
- lib/auth/service.rb
---
## Purpose
Ruby auth service with JWT validation.
## Public API
| Symbol | Kind | Description |
|--------|------|-------------|
| `Authentication` | module | Auth namespace |
| `AuthService` | class | Auth service class |
| `validate` | method | Validates a JWT token |
| `DEFAULT_TTL` | constant | Default TTL in seconds |
| `token` | attr_reader | Token accessor |
## Change Log
| Date | Change |
|------|--------|
| 2026-01-01 | Initial | Source
module Authentication
class AuthService
DEFAULT_TTL = 3600
attr_reader :token, :expires_at
def validate(token)
!token.nil? && !token.empty?
end
def self.create(config)
new(config)
end
private
def internal_check
# internal
end
end
end Test-file patterns
Files matching these are excluded from the detected surface.
| Pattern | Explanation |
|---|---|
**/*_test.rb | minitest-style test files: auto-excluded |
**/*_spec.rb | RSpec spec files: auto-excluded |
Caveats
- Visibility tracking resets at the start of each class/module scope; nested classes start as public again.
- Method aliases (alias_method :new_name, :old_name) are not captured as additional exports.
- Dynamic method definitions (define_method :name do ... end) are not detected.
- Rails-specific DSL exports (has_many, belongs_to, scope, etc.) are not captured.