Mario Zigliotto
Mario Zigliotto

Reputation: 9025

How to delete a Node from a Nokogiri Nodeset?

I have a nodeset in the variable my_nodeset

I'd like to remove the last node that was found.

Initially i expected this to work: my_nodeset.last.remove but it does not.

The only way I've found to remove the last item is with something like this: my_nodeset.delete(my_nodeset.last)

Seems strange to me and i was wondering if there's a "correct" way to do it. Thanks!

Upvotes: 2

Views: 1240

Answers (1)

dierre
dierre

Reputation: 7210

It is not strange to me.

my_nodeset.last.remove means:

call Nodeset my_nodeset then go to its last Node member and call remove method (owned by last). You want to ask to a Node method to modify a NodeSet. That's semantically wrong to me.

my_nodeset.delete(my_nodeset.last) is how it should be.

Upvotes: 3

Related Questions