Skip to content

Conversation

@marshall-lee
Copy link
Contributor

@marshall-lee marshall-lee commented Jan 17, 2025

Description

Data was added in Ruby 3.2. This is similar to Struct but immutable and with kwargs by default. So this PR aims to support simple Data.define const assignments:

Foo = Data.define(:a, :b, :c)
Foo::Bar = Data.define(:a, :b, :c)
Baz = Data.define(:a, :b, :c) do
  def d; end
end

Note: the support of the class Foo < Data.define(:a, :b) form was not added by intention because I don't want to encourage this style of programming and it does not appear in the Data documentation. If one has a strong opinion that this style must be supported, they're free to do it in a separate PR.

Completed Tasks

  • I have read the Contributing Guide.
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).

@lsegal lsegal merged commit 18845c9 into lsegal:main May 9, 2025
@lsegal
Copy link
Owner

lsegal commented May 9, 2025

Great change, thank you!

@marshall-lee marshall-lee deleted the data-define branch August 28, 2025 23:21
@marshall-lee
Copy link
Contributor Author

@lsegal Hi! May I ask you when this will be released?

myronmarston added a commit to block/elasticgraph that referenced this pull request Dec 17, 2025
YARD 0.9.38 parses `MyClass = Data.define(...)` for the first time:

lsegal/yard#1600

There are 3 spots in this codebase that `be rake site:docs_coverage`
reported as uncovered on YARD 0.9.38. This addresses all three.
myronmarston added a commit to block/elasticgraph that referenced this pull request Dec 17, 2025
YARD 0.9.38 parses `MyClass = Data.define(...)` for the first time:

lsegal/yard#1600

There are 3 spots in this codebase that `be rake site:docs_coverage`
reported as uncovered on YARD 0.9.38. This addresses all three.
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.

2 participants