Skip to content

Support custom members of Data class and Struct class#183

Open
tk0miya wants to merge 3 commits intosoutaro:mainfrom
tk0miya:data_assign/block
Open

Support custom members of Data class and Struct class#183
tk0miya wants to merge 3 commits intosoutaro:mainfrom
tk0miya:data_assign/block

Conversation

@tk0miya
Copy link
Copy Markdown
Contributor

@tk0miya tk0miya commented Jan 12, 2025

Data class and Struct class can define custom members via block:

Measure = Data.define(:amount, :unit) do
  def <=>(other)
    return unless other.is_a?(self.class) && other.unit == unit
    amount <=> other.amount
  end
    
  include Comparable
end

This generates type definitions for these custom members.

refs:

Data class can define custom members via block:

```ruby
Measure = Data.define(:amount, :unit) do
  def <=>(other)
    return unless other.is_a?(self.class) && other.unit == unit
    amount <=> other.amount
  end

  include Comparable
end
```

This generates type definitions for these custom members.

ref: https://ruby-doc.org/3.4.1/Data.html
tk0miya pushed a commit to tk0miya/rubocop-rbs_inline that referenced this pull request Feb 21, 2026
tk0miya pushed a commit to tk0miya/rubocop-rbs_inline that referenced this pull request Feb 21, 2026
RBS::Inline does not parse block contents in `Data.define` calls,
so methods defined inside such blocks are not recognized for type
checking. This new cop detects the pattern and guides users to use
a separate `Data.define` call followed by a class reopening.

This is a known limitation of RBS::Inline. See
soutaro/rbs-inline#183 for the upstream fix.

https://claude.ai/code/session_018NGR1GYyr9VMLScVdNabAh
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