ruby / ruby/rbs

How to deal a module included by a specified class like ActiveRecord::Base?

Open
#1,108 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

I write a concern module that supposes to be included by ActiveRecord::Base's subclass.

like following,

module A
  extend ActiveSupport::Concern
  included do
    has_many :hoge
  end

  def bar
    save
  end
end

In such a case, module A supposes to have ActiveRecord::Base methods.
But, in the current RBS, developers must write all ActiveRecord::Base method signatures by themselves.
Because module cannot inherit class and class cannot be included (extended).

I want a helper syntax to include method signatures of other classes whether are not modules or interfaces.

For example:

module A
  included_by ActiveRecord::Base # define method signatures with ActiveRecord::Base type
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed RBS syntax for module A and the ActiveRecord::Base example in the issue. Determine how signatures from a specified class should be exposed to an included module, including the interaction with ActiveSupport::Concern. Done means the behavior and syntax are defined well enough to support this use case without requiring developers to duplicate ActiveRecord::Base signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.