[#78633] ruby/spec needs help from CRuby committers — Benoit Daloze <eregontp@...>

Currently, ruby/spec is maintained mostly by individuals and enjoys the

13 messages 2016/12/13

[ruby-core:78713] Re: [Ruby trunk Feature#13045] Passing a Hash with String keys as keyword arguments

From: Daniel Ferreira <subtileos@...>
Date: 2016-12-17 18:25:11 UTC
List: ruby-core #78713
This is a problem that bothers me a lot.
The amount of time I lose thinking about symbol vs string in a hash
justifies my reply to this thread.
I don't know what are the implications but the in an ideal world string and
symbol should represent the same key. That would make my life so much
better when designing a ruby interface.

On Sat, 17 Dec 2016 at 15:45, <shevegen@gmail.com> wrote:

> Issue #13045 has been updated by Robert A. Heiler.
>
>
>
>
>
> I would agree with a **way/method to convert string-keys into
> symbol-keys**.
>
>
>
> I have no idea if this should be Hash#symbolize_keys or another name -
> perhaps
>
> #transform_keys and allow either to_string or to_symbol conversion - but I
>
> agree with a convenience method that could turn keys into one or the other.
>
>
>
> Perhaps this would also reduce the need for strange things such as
>
> HashWithIndifferentAccess. Newcomers will always wonder whether they should
>
> use strings or symbols (or even worse, both at the same time in the same
>
> hash).
>
>
>
> ----------------------------------------
>
> Feature #13045: Passing a Hash with String keys as keyword arguments
>
> https://bugs.ruby-lang.org/issues/13045#change-62084
>
>
>
> * Author: Anatoly Chernow
>
> * Status: Open
>
> * Priority: Normal
>
> * Assignee:
>
> * Target version:
>
> ----------------------------------------
>
> To the following method
>
>
>
> ~~~ ruby
>
> def new request:, response:
>
> end
>
> ~~~
>
> I'd like to be able to pass both
>
>
>
> ~~~ ruby
>
> hash_with_symbol_keys = { request: another_hash, response: another_hash2 }
>
> hash_with_string_keys = { 'request' => another_hash, 'response' =>
> another_hash2 }
>
> ~~~
>
>
>
> I would make a lot cleaner parsing many things returned with string
> keys(like the output of `YAML.load`).
>
>
>
> If you don't like the above feature, could you please at least consider
> adding `Hash#symbolize_keys`(like you did with `Hash#transform_values`)?
>
>
>
>
>
>
>
> --
>
> https://bugs.ruby-lang.org/
>
>
>
> Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
>
>

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next