Forum: Ruby where is the each_recursive method defined?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1fec2e21639542870dbd53c92855051f?d=identicon&s=25 snailigrape (Guest)
on 2005-11-16 09:04
(Received via mailing list)
#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
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 leavengood (Guest)
on 2005-11-16 20:12
(Received via mailing list)
On 11/16/05, snailigrape@yahoo.com.cn <snailigrape@yahoo.com.cn> 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
This topic is locked and can not be replied to.