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

Enhancement: Add #key? #value? predicates to Node #1838

Closed
MatzFan opened this issue Dec 13, 2018 · 5 comments
Closed

Enhancement: Add #key? #value? predicates to Node #1838

MatzFan opened this issue Dec 13, 2018 · 5 comments

Comments

@MatzFan
Copy link
Contributor

MatzFan commented Dec 13, 2018

Was gonna PR you this with (of course) tests, but couldn't figure out why my new methods were not found and the whole tmp folder builds thing. And then I read Y_U_NO_GEMSPEC.

Rationale:
Rubocop bugs me that instead of iterating a Nokogiri::XML::Node using .keys.include? or .values.include? I should be using hash #key? or #value? methods. As Node is a hash-like object I figured why not add them.

Code

def  keys?(key)
  keys.include? key
end

def value?(value)
  values.include? value
end
@flavorjones
Copy link
Member

Hi! Thanks for opening this request.

FYI - you can create a temporary local gemspec for testing by running rake gem:spec (you'll need to make sure you've got the hoe-gemspec gem installed as well).

I'd accept a PR for this functionality. If you're unsure how to go about doing it, I'm happy to collaborate with you on it.

@knu
Copy link
Member

knu commented Dec 13, 2018

I can think of how key? could be useful, but I'm not sure about value?.

@knu
Copy link
Member

knu commented Dec 13, 2018

And I think we already have key?.

@MatzFan
Copy link
Contributor Author

MatzFan commented Dec 14, 2018

@knu - quite right, just #value? missing. Re a use case, it is quite possible what I was trying to do can be accomplished a better way with existing functionality - FWIW I was trying to find a node with a particular attribute value. Nevertheless, I just felt it may be good practice for hash-like objects to, as far as possible, replicate Ruby's Hash interface.

Thanks @flavorjones think I figured it out, PR on the way.

@flavorjones flavorjones added this to the v1.11.0 milestone Jan 5, 2019
@flavorjones
Copy link
Member

Will be in v1.11.0.

This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants