where is the each_recursive method defined?

S

snailigrape

#i'm new to ruby. i download the machanize gem and install it.
in machanize.rb , root_node has an each_recursive method,but i can't
fine the definition in docs. who can tell me what to do,thanks in
advance.

def self.extract_all_from(root_node)
fields = []
root_node.each_recursive {|node|
if (node.name.downcase == 'input' and
%w(text password hidden checkbox radio
int).include?(node.attributes['type'].downcase)) or
%w(textarea option).include?(node.name.downcase)
fields << Field.new(node.attributes['name'],
node.attributes['value'])
end
}
return fields
end
 
R

Ryan Leavengood

#i'm new to ruby. i download the machanize gem and install it.
in machanize.rb , root_node has an each_recursive method,but i can't
fine the definition in docs. who can tell me what to do,thanks in
advance.

def self.extract_all_from(root_node)
fields =3D []
root_node.each_recursive {|node|
if (node.name.downcase =3D=3D 'input' and
%w(text password hidden checkbox radio
int).include?(node.attributes['type'].downcase)) or
%w(textarea option).include?(node.name.downcase)
fields << Field.new(node.attributes['name'],
node.attributes['value'])
end
}
return fields
end

It is part of additions made to the REXML library by mechanize, in
mechanize/parsing.rb:

module REXML::Node

# Visit all subnodes of +self+ recursively

def each_recursive(&block) # :yields: node
self.elements.each {|node|
block.call(node)
node.each_recursive(&block)
}
end

I hope that explains to you what it does.

Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top