Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support A = Data.define(:a, :b, :c) #1600

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marshall-lee
Copy link

@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).

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