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

returns nil if xpath_nodes is empty #3172

Merged
merged 2 commits into from
Aug 18, 2016
Merged

Conversation

mgxm
Copy link

@mgxm mgxm commented Aug 17, 2016

When you search for xpath_node and this node doesn't exist, will raise Enumerable::EmptyError.
I wondering if not found, just return nil.
Don't know if is the best approach to do that, maybe I can implement this in XML::XPathContext::evaluate

# ```
# node.xpath_node("//person")
# ```
def xpath_node(path, namespaces = nil, variables = nil)
xpath_nodes(path, namespaces).first
xpath = xpath_nodes(path, namespaces)
xpath.empty? ? nil : xpath.first
Copy link
Member

Choose a reason for hiding this comment

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

xpath_nodes(path, namespaces).first? should work equally.

@asterite
Copy link
Member

Thank you!

@asterite asterite merged commit d93e740 into crystal-lang:master Aug 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants