Skip to content

[Ruby]Implement #to_hash for message classes #20866

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

Closed
wants to merge 1 commit into from

Conversation

y-yagi
Copy link
Contributor

@y-yagi y-yagi commented Mar 27, 2025

In Ruby, #to_hash is used for implicit conversion. https://bugs.ruby-lang.org/issues/10180

For example, Active Support uses #to_hash when converting an object to JSON. https://github.com/rails/rails/blob/621aa49cefce3313fbc672e2f3681103da686a0e/activesupport/lib/active_support/core_ext/object/json.rb#L60

This PR adds #to_hash as the alias of #to_h. This allows message objects to convert implicitly to other formats correctly.

Fixes #17037

In Ruby, `#to_hash` is used for implicit conversion.
https://bugs.ruby-lang.org/issues/10180

For example, Active Support uses `#to_hash` when converting an object to JSON.
https://github.com/rails/rails/blob/621aa49cefce3313fbc672e2f3681103da686a0e/activesupport/lib/active_support/core_ext/object/json.rb#L60

This PR adds `#to_hash` as the alias of `#to_h`. This allows
message objects to convert implicitly to other formats correctly.

Fixes protocolbuffers#17037
@y-yagi y-yagi requested a review from a team as a code owner March 27, 2025 02:53
@y-yagi y-yagi requested review from JasonLunn and removed request for a team March 27, 2025 02:53
@Dustin4444
Copy link

In Ruby, #to_hash is used for implicit conversion. https://bugs.ruby-lang.org/issues/10180

For example, Active Support uses #to_hash when converting an object to JSON. https://github.com/rails/rails/blob/621aa49cefce3313fbc672e2f3681103da686a0e/activesupport/lib/active_support/core_ext/object/json.rb#L60

This PR adds #to_hash as the alias of #to_h. This allows message objects to convert implicitly to other formats correctly.

Fixes #17037

@JasonLunn JasonLunn added the ruby label Mar 27, 2025
@JasonLunn JasonLunn added 🅰️ safe for tests Mark a commit as safe to run presubmits over wait for user action labels Mar 27, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Mar 27, 2025
@JasonLunn JasonLunn added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Mar 27, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Mar 27, 2025
@y-yagi
Copy link
Contributor Author

y-yagi commented Mar 28, 2025

It seems that there is a wait for user action label in this PR. Should I do something? 🙏

@JasonLunn JasonLunn added 🅰️ safe for tests Mark a commit as safe to run presubmits over and removed wait for user action labels Mar 28, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Mar 28, 2025
@y-yagi y-yagi deleted the fixes_17037 branch March 29, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 participants