-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Sinatra::IndifferentHash does not support initialization with any hash or key-value pair list #1948
Comments
This looks like an intentional omission by 44c3cb8 (#1279) (6 years ago), as this was possible with Also: $ irb
irb(main):001:0> Hash.new(a: 1)
=> {} Maybe @mwpastore or @jkowens want to weigh in |
Though the documentation comments should probably be updated: sinatra/lib/sinatra/indifferent_hash.rb Lines 22 to 32 in e130771
Looks like they were just copied and some search-and-replace was done |
Interesting that it was an intentional omission. Thanks for the information, @dentarg . 🙇 Is there a known explanation for why the current I guess if its not a bug, do you think a feature addition proposal has a chance of acceptance? |
I'm leaning towards that we shouldn't add that to Sinatra, as less code is less code to maintain, and the Sinatra project is very short on maintainers and maintainers time. Sinatra is not Rails/ActiveSupport so we shouldn't need to mimic every aspect of it. I'm open to hear thoughts from the rest of @sinatra/sinatras-helpers though |
Instead, time could be better spent on allowing users of Sinatra to use |
@dentarg - Those are good recommendations. For myself personally, I don't have any trouble using ActiveSupport instead, since it's required by another project dependency already. I also have a work-around for the unsupported I suppose what I'm really asking is, how difficult generally is contribution to Sinatra? I enjoy writing ruby code, and I'd be happy to commit some personal time to it. What is your opinion on such a contribution proposal? I find myself wanting to use |
Currently ex:
The documentation definitely should be updated to make that clear. |
I see. Well, I suppose I'll close this issue, then. Thanks for the discussion, everyone. |
Let's keep it open until the documentation has been updated, so we don't forget. |
Resolves #1948. Looking over the code, I'm not sure that the `initialize` method makes sense to me. ``` def initialize(*args) args.map!(&method(:convert_value)) super(*args) end ``` I don't know why you'd want to call `convert_value` on a value that's been specified as a default value when a key is missing. See https://ruby-doc.org/3.2.2/Hash.html#method-c-new ``` h = Sinatra::IndifferentHash.new(a: 1) h[:b] = {"a" => 1 } ``` I'm thinking maybe that should be removed to eliminate possible confusion? Co-authored-by: Patrik Ragnarsson <patrik@starkast.net>
See these links for background: - sinatra#1951 - sinatra#1948 Before > Sinatra::IndifferentHash.new(a: 1)[:b] => {"a"=>1} After > Sinatra::IndifferentHash.new(a: 1)[:b] => {:a=>1} Close sinatra#1953
In short, the following snippet from https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html does not work:
Instead, this is what happens with
Sinatra::IndifferentHash
:The text was updated successfully, but these errors were encountered: