where is the each_recursive method defined?

Discussion in 'Ruby' started by snailigrape@yahoo.com.cn, Nov 16, 2005.

  1. Guest

    #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
     
    , Nov 16, 2005
    #1
    1. Advertising

  2. On 11/16/05, <> 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 =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
     
    Ryan Leavengood, Nov 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oodini
    Replies:
    1
    Views:
    1,775
    Keith Thompson
    Sep 27, 2005
  2. mike
    Replies:
    5
    Views:
    339
    Ben Pope
    Feb 22, 2006
  3. Angel Tsankov
    Replies:
    1
    Views:
    870
    Victor Bazarov
    Apr 5, 2006
  4. Replies:
    1
    Views:
    504
    Sion Arrowsmith
    Jul 10, 2008
  5. aidy
    Replies:
    5
    Views:
    237
    Marcin Mielżyński
    Jun 4, 2006
Loading...

Share This Page