Where is the each_recursive method defined?


#1

#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


#2

On 11/16/05, removed_email_address@domain.invalid removed_email_address@domain.invalid wrote:

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