Skip to content
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

params can't be used as keyword arguments #1592

Open
baelter opened this issue Feb 13, 2020 · 2 comments
Open

params can't be used as keyword arguments #1592

baelter opened this issue Feb 13, 2020 · 2 comments

Comments

@baelter
Copy link
Contributor

baelter commented Feb 13, 2020

We can't pass params hash and expect keyword args to be matched because of the current IndifferentHash implementation.

def a(a:, **); end
a(Hash[a: 1]) # => nil
a(Sinatra::IndifferentHash[a: 1]) # => ArgumentError (wrong number of arguments (given 1, expected 0; required keyword: a))
a(**Sinatra::IndifferentHash[a: 1]) # => TypeError (hash key "a" is not a Symbol)

Changing the IndifferentHash private method convert_key to always return key.to_s.to_sym solves this.

@jkowens
Copy link
Member

jkowens commented Mar 18, 2020

This issue has also been brought up in the Rails project. Since this models ActiveSupport::HashWithIndifferentAccess I would like to stay in line with the approach there. I'm wondering if we can also provide a method symbolize_keys that will serve as a work around.

See:

rails/rails#14643

https://bugs.ruby-lang.org/issues/9731

https://til.hashrocket.com/posts/d66e55091c-hashwithindifferentaccess-for-keyword-arguments

@baelter
Copy link
Contributor Author

baelter commented Mar 30, 2020

Okey, maybe it can be done as an opt-in setting. I'll look into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants