From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 7DAF81F4B4 for ; Mon, 28 Dec 2020 03:42:09 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2C161120A75; Mon, 28 Dec 2020 12:41:20 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3F6AB120A74 for ; Mon, 28 Dec 2020 12:41:18 +0900 (JST) Received: by filterdrecv-p3mdw1-7474cd8bfd-d66mf with SMTP id filterdrecv-p3mdw1-7474cd8bfd-d66mf-19-5FE95406-E 2020-12-28 03:41:58.364702921 +0000 UTC m=+1485575.388900711 Received: from herokuapp.com (unknown) by ismtpd0089p1iad2.sendgrid.net (SG) with ESMTP id yOtKvrslRhObSiDmm9uIgA for ; Mon, 28 Dec 2020 03:41:58.295 +0000 (UTC) Date: Mon, 28 Dec 2020 03:41:58 +0000 (UTC) From: naruse@airemix.jp Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 77669 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17472 X-Redmine-Issue-Author: naruse X-Redmine-Sender: naruse X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?UqoG4vcRhHM9V1I4f4J7DhjzUfTg+8muXbMD6UD+LVQdTMIVVfzZgwGwnaxqQg?= =?us-ascii?Q?nuqN0Q0aIJ1sNI+CJ9wD1P+SegGXgS62sVuIR5X?= =?us-ascii?Q?yfr37bztiGpInrBvbPXyRORN=2F6mo1LVw03CbX2E?= =?us-ascii?Q?6rRJ1X0Z0M=2FOIXEGI+ciSR4+pmK1qteUdKkOTTG?= =?us-ascii?Q?mRzNLrq69p2j5dNEU=2F7cgvnA=2Fc541VN317MWGO1?= =?us-ascii?Q?aUA9x6XM9jLNgL9F8=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 101767 Subject: [ruby-core:101767] [Ruby master Feature#17472] HashWithIndifferentAccess like Hash extension X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17472 has been updated by naruse (Yui NARUSE). My intention is * A feature to implement Rails's ActiveSupport::HashWithIndifferentAccess, not providing HashWithIndifferentAccess itself. * the key of internal hash should be symbol though ActiveSupport::HashWithIndifferentAccess uses String as key. * rails doesn't depend C extension. I added a link to kamipo's summary as more context https://github.com/rails/rails/pull/40182#issuecomment-687607812 Dan0042 (Daniel DeLorme) wrote in #note-6: > I'm also against this, but I think a more general-purpose version might be ok. In my code I use a `NormalizedHash` class which calls `key = normalize(key)` for every method with a `key` argument (as well as `merge`, etc.) I use this base class to define subclasses with specific `normalize` methods; `HeaderHash` converts keys to Http-Header-Camelcase, `OptionsHash` raises an error if the key is not a Symbol. Something that can be used as the basis of different implementations (including `HashWithIndifferentAccess`) might make sense in the stdlib. Might. You can use Hash#compare_by_identity (https://ruby-doc.org/core-2.7.1/Hash.html#method-i-compare_by_identity). ---------------------------------------- Feature #17472: HashWithIndifferentAccess like Hash extension https://bugs.ruby-lang.org/issues/17472#change-89595 * Author: naruse (Yui NARUSE) * Status: Open * Priority: Normal * Target version: 3.1 ---------------------------------------- Rails has [ActiveSupport::HashWithIndifferentAccess](https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html), which is widely used in Rails to handle Request, Session, ActionView's form construction, ActiveRecord's DB communication, and so on. It receives String or Symbol and normalize them to fetch the value. But it is implemented with Ruby. If we provide C implementation of that, Rails will gain the performance improvement. summary of previous discussion: https://github.com/rails/rails/pull/40182#issuecomment-687607812 -- https://bugs.ruby-lang.org/