summaryrefslogtreecommitdiff
path: root/lib/rexml/node.rb
diff options
context:
space:
mode:
authorser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-19 03:51:53 +0000
committerser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-19 03:51:53 +0000
commited512acb2fd71016e320414a16b3262ce2f9c366 (patch)
tree2e3a631d82871b691dc1a7c0633033fa04ff8d2f /lib/rexml/node.rb
parentd4d497dd86962d333337b70392623ccde5a053c2 (diff)
Cross-ported the REXML changes from HEAD to the 1.8 branch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/node.rb')
-rw-r--r--lib/rexml/node.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/rexml/node.rb b/lib/rexml/node.rb
index 5f414c03ef..e5dec72a9d 100644
--- a/lib/rexml/node.rb
+++ b/lib/rexml/node.rb
@@ -36,5 +36,31 @@ module REXML
def parent?
false;
end
+
+
+ # Visit all subnodes of +self+ recursively
+ def each_recursive(&block) # :yields: node
+ self.elements.each {|node|
+ block.call(node)
+ node.each_recursive(&block)
+ }
+ end
+
+ # Find (and return) first subnode (recursively) for which the block
+ # evaluates to true. Returns +nil+ if none was found.
+ def find_first_recursive(&block) # :yields: node
+ each_recursive {|node|
+ return node if block.call(node)
+ }
+ return nil
+ end
+
+ # Returns the index that +self+ has in its parent's elements array, so that
+ # the following equation holds true:
+ #
+ # node == node.parent.elements[node.index_in_parent]
+ def index_in_parent
+ parent.index(self)+1
+ end
end
end