diff options
| author | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 03:51:53 +0000 |
|---|---|---|
| committer | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 03:51:53 +0000 |
| commit | 6769c8ce5944dc0ae283ac5a1e46a9f1717d6851 (patch) | |
| tree | 2e3a631d82871b691dc1a7c0633033fa04ff8d2f /lib/rexml/node.rb | |
| parent | fa8573da6ad626b7b368362ee15972bdb17e75ca (diff) | |
| download | ruby-6769c8ce5944dc0ae283ac5a1e46a9f1717d6851.tar.gz ruby-6769c8ce5944dc0ae283ac5a1e46a9f1717d6851.tar.xz ruby-6769c8ce5944dc0ae283ac5a1e46a9f1717d6851.zip | |
Cross-ported the REXML changes from HEAD to the 1.8 branch.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/node.rb')
| -rw-r--r-- | lib/rexml/node.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/rexml/node.rb b/lib/rexml/node.rb index 5f414c03e..e5dec72a9 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 |
