From: janosch-x via ruby-core Date: 2023-04-21T15:39:38+00:00 Subject: [ruby-core:113310] [Ruby master Feature#19607] Introduce `Hash#symbolize_keys`. Issue #19607 has been updated by janosch-x (Janosch M��ller). nobu (Nobuyoshi Nakada) wrote in #note-4: > I have never needed such operation. > What���s the use case? dealing with data from uncontrolled sources, supporting multiple sources of config data (e.g. YML, JSON, code etc.), and making a less picky interface in general. some examples: - [faker interface](https://github.com/faker-ruby/faker/blob/6aae8e21e1eaf9ae845017a86c62ae44c9d91654/lib/faker/default/address.rb#L341) - [pg config](https://github.com/ged/ruby-pg/blob/2e663b34745c9a91610bfb58b42cd6ecafc2331f/lib/pg/connection.rb#L64) - [redis config](https://github.com/redis/redis-rb/blob/4e9d73d3bb47831fe720cbce7c47cb11dd3f4de9/lib/redis/cluster/option.rb#L82) - [solargraph interface](https://github.com/castwide/solargraph/blob/d48f3963d1ce19b369efbc7f0327b27767fc7b0c/lib/solargraph/language_server/message/completion_item/resolve.rb#L24) - [interface in ruby/optparse](https://github.com/ruby/ruby/blob/39bbbd767d6465080c6e1d6ba0da98c2762eedc6/lib/optparse.rb#L1816) (this is btw another precedent/occurrence of `symbolize_names` outside JSON and Psych). ---------------------------------------- Feature #19607: Introduce `Hash#symbolize_keys`. https://bugs.ruby-lang.org/issues/19607#change-102867 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- This is a very common operation. It can currently be implemented using `Hash#transform_keys(&:to_sym)`. It's currently provided by Rails as `Hash#symbolize_keys` and `Hash#symbolize_keys!`. Proposed implementation is identical to Rails implementation: https://github.com/rails/rails/blob/539144d2d61770dab66c8643e744441e52538e09/activesupport/lib/active_support/core_ext/hash/keys.rb#L20-L37 For completeness we could also consider adding `stringify_keys` but I think that's less frequently used. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/