From: Ryan Leavengood Date: 2005-11-17T04:09:47+09:00 Subject: Re: where is the each_recursive method defined? On 11/16/05, snailigrape@yahoo.com.cn wrote: > #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 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