Skip to content

Add extend support for module methods as class methods#67

Merged
dak2 merged 1 commit into
mainfrom
add-extend-support
Mar 17, 2026
Merged

Add extend support for module methods as class methods#67
dak2 merged 1 commit into
mainfrom
add-extend-support

Conversation

@dak2

@dak2 dak2 commented Mar 17, 2026

Copy link
Copy Markdown
Owner

Motivation

extend ModuleName makes module instance methods available as class methods, but Method-Ray currently reports false positives (e.g., User.find → "undefined method") because Singleton type resolution has no fallback for extended modules. This is a common Ruby pattern used widely in Rails and other frameworks.

Changes

  • Add MixinKind enum to unify include/extend handling, replacing IncludeDeclaration with ModuleMixinDeclaration
  • Extract extract_mixin_module_names helper to eliminate code duplication between include and extend
  • Add module_extensions field to GlobalEnv with record_extend() method and shared record_mixin helper
  • Add extensions to ResolutionContext and search extended modules in fallback_chain() for Type::Singleton types
  • def self.method takes priority over extend (exact match first)

Checked

  • Rust unit tests — method_registry: 4 extend cases, dispatch: 7 extend cases
  • Ruby integration test — test/extend_test.rb

🤖 Generated with Claude Code

Enable `extend ModuleName` to make module instance methods available
as class methods (singleton methods) on the extending class. Unifies
include/extend handling via MixinKind enum to reduce code duplication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dak2 dak2 merged commit eeeaf79 into main Mar 17, 2026
4 checks passed
@dak2 dak2 deleted the add-extend-support branch March 17, 2026 14:46
@dak2 dak2 mentioned this pull request Mar 24, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant