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

Slice doesn't work using symbols #529

Closed
jcavalieri opened this issue Sep 17, 2020 · 5 comments
Closed

Slice doesn't work using symbols #529

jcavalieri opened this issue Sep 17, 2020 · 5 comments
Labels
bug? hacktoberfest Issues that would be suitable for Hacktoberfest

Comments

@jcavalieri
Copy link

Hi Hashie Team,

It appears that slice is not working. I noticed this when upgrading from ruby 2.4.5 to 2.5.8.

We had been using hashie 3.6. Upgrading to hashie 4.1 produced the same results.

Slice only seems to work with strings not symbols. Here is some test code:

require 'hashie'

class MyHash < Hash
  include Hashie::Extensions::IndifferentAccess
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::DeepFind
  include Hashie::Extensions::DeepLocate
end

my_hash = MyHash[test: 'a value']

puts "This works: #{my_hash.slice('test')}"
puts "This doesn't: #{my_hash.slice(:test)}"

output looks like this:
This works: {"test"=>"a value"}
This doesn't: {}

@jcavalieri
Copy link
Author

Also, it appears that my_hash.slice('test') returns a Hash.

@dblock dblock added the bug? label Sep 18, 2020
@dblock
Copy link
Member

dblock commented Sep 18, 2020

Looks like a legit bug/non feature. Feel free to PR!

@jcavalieri
Copy link
Author

Is there a spot in the codebase that would be a similar solution? I.e. overriding a Hash method. Something I could look at as an example?

@michaelherold
Copy link
Member

michaelherold commented Sep 24, 2020

This is likely due to IndifferentAccess. The fix probably is to call #convert_key #indifferent_reader on each of the arguments to #slice.

@michaelherold michaelherold added the hacktoberfest Issues that would be suitable for Hacktoberfest label Sep 30, 2020
gnomex added a commit to gnomex/hashie that referenced this issue Oct 1, 2020
gnomex added a commit to gnomex/hashie that referenced this issue Oct 1, 2020
gnomex added a commit to gnomex/hashie that referenced this issue Oct 1, 2020
@michaelherold
Copy link
Member

Closed via #531

@jgr jgr mentioned this issue Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug? hacktoberfest Issues that would be suitable for Hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants