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

add hash slice using IndifferentAccess #531

Closed
wants to merge 3 commits into from

Conversation

gnomex
Copy link
Contributor

@gnomex gnomex commented Oct 1, 2020

Add hash#slice using IndifferentAccess extension to fix #529

I just not sure if I need to add with_minimum_ruby('2.5.0'), because it is only available from version 2.5.

Example

class MyHash < Hash
  include Hashie::Extensions::IndifferentAccess
end

my_hash = MyHash[test: 'a value']

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

@gnomex gnomex force-pushed the slice-with-indifferent-access branch from d4d7459 to 300cb88 Compare October 1, 2020 11:58
@dblock
Copy link
Member

dblock commented Oct 1, 2020

  • If it's not available < 2.5, you will need to add with_minimum_ruby
  • Run rubocop -a ; rubocop --auto-gen-config for the Rubocop issue.

@gnomex
Copy link
Contributor Author

gnomex commented Oct 3, 2020

wrapped slice with with_minimum_ruby.

About the rubocop issue, since config includes

Metrics/ClassLength:
  Enabled: false

I just did the same to Module:

Metrics/ModuleLength:
  Enabled: false

It makes sense?

Copy link
Collaborator

@BobbyMcWho BobbyMcWho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -36,6 +36,7 @@ Any violations of this scheme are considered to be bugs.
### Fixed

* [#516](https://github.com/hashie/hashie/issues/516): Fixed `NoMethodError` raised when including `Hashie::Extensions::Mash::SymbolizeKeys` and `Hashie::Extensions::SymbolizeKeys` in mashes/hashes with non string or symbol keys - [@carolineartz](https://github.com/carolineartz).
* [#531](https://github.com/hashie/hashie/pull/531): Fixed [slice doesn't work using symbols](https://github.com/hashie/hashie/issues/529) using hash with `IndifferentAccess` extension - [@gnomex](https://github.com/gnomex)
Copy link
Member

@dblock dblock Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a period in the end to match other lines, please.

@dblock
Copy link
Member

dblock commented Oct 3, 2020

Merged via 792714b.

@dblock dblock closed this Oct 3, 2020
@michaelherold michaelherold added the hacktoberfest-accepted Accepted changes for Hacktoberfest label Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Accepted changes for Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slice doesn't work using symbols
4 participants