summaryrefslogtreecommitdiffstats
path: root/lib/rexml/element.rb
diff options
context:
space:
mode:
authorser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-08 02:03:44 +0000
committerser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-08 02:03:44 +0000
commited71c064d5162f269336f3baed43c28aafd76094 (patch)
tree5e6ceeb9a9fcb13bfba05d7eef0b49d398f78a76 /lib/rexml/element.rb
parentd9dfe3ad2b1d51a3217a02353662dd211e9adf7d (diff)
downloadruby-ed71c064d5162f269336f3baed43c28aafd76094.tar.gz
ruby-ed71c064d5162f269336f3baed43c28aafd76094.tar.xz
ruby-ed71c064d5162f269336f3baed43c28aafd76094.zip
Merged changes into HEAD from REXML 3.1.5.
The list of bug fixes/enhancements is at: http://www.germane-software.com/projects/rexml/query?status=closed&milestone=3.1.5 git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/element.rb')
-rw-r--r--lib/rexml/element.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index 80463d95b..435076420 100644
--- a/lib/rexml/element.rb
+++ b/lib/rexml/element.rb
@@ -938,6 +938,29 @@ module REXML
def each( xpath=nil, &block)
XPath::each( @element, xpath ) {|e| yield e if e.kind_of? Element }
end
+
+ def collect( xpath=nil, &block )
+ collection = []
+ XPath::each( @element, xpath ) {|e|
+ collection << yield(e) if e.kind_of?(Element)
+ }
+ collection
+ end
+
+ def inject( xpath=nil, initial=nil, &block )
+ first = true
+ XPath::each( @element, xpath ) {|e|
+ if (e.kind_of? Element)
+ if (first and initial == nil)
+ initial = e
+ first = false
+ else
+ initial = yield( initial, e ) if e.kind_of? Element
+ end
+ end
+ }
+ initial
+ end
# Returns the number of +Element+ children of the parent object.
# doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'