mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Merged changes 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 Merged Nobu's & DrBrain's changes into REXML head. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1838ddd7ae
commit
8935ae596b
7 changed files with 83 additions and 43 deletions
|
@ -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>'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue