SIGN IN SIGN UP

Protocol Buffers - Google's data interchange format

0 0 2 C++

[Ruby]Implement `#to_hash` for message classes (#20866)

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

Closes #20866

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/20866 from y-yagi:fixes_17037 e0422bb573910ac0374981810d3e991737f1e033
PiperOrigin-RevId: 741713385
Y
y-yagi committed
5596f6d8afc72e99c19d2c72e8d39e6d2e88acf4
Parent: aaa3f52
Committed by Copybara-Service <copybara-worker@google.com> on 3/29/2025, 2:18:16 AM