Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Traversal error on Module #3

Open
kristianmandrup opened this Issue Apr 2, 2010 · 0 comments

Comments

Projects
None yet
1 participant
Collaborator

kristianmandrup commented Apr 2, 2010

  define_method :"test select on a Module" do
    nodes = build('module Hello end').select(Ruby::Module)
    assert_equal 1, nodes.size
  end
Ruby::Module
#, @parent=#>, @ldelim=nil, @rdelim=nil, @parent=#>, @body=[:bodystmt, #>, nil, nil, nil], @ldelim=#, @parent=#>, @rdelim=#, @parent=#>, @parent=#]>>
Ruby::Token
#, @parent=#, @parent=#>, @ldelim=nil, @rdelim=nil, @parent=#>, @body=[:bodystmt, #>, nil, nil, nil], @ldelim=#, @rdelim=#, @parent=#>, @parent=#]>>>
Ruby::Const
#, @parent=#>, @ldelim=nil, @rdelim=nil, @parent=#, @body=[:bodystmt, #>, nil, nil, nil], @ldelim=#, @parent=#>, @rdelim=#, @parent=#>, @parent=#]>>>
Ruby::Whitespace
" "
Ruby::Identifier
#, @parent=#, @ldelim=nil, @rdelim=nil, @parent=#, @body=[:bodystmt, #>, nil, nil, nil], @ldelim=#, @parent=#>, @rdelim=#, @parent=#>, @parent=#]>>>>
Ruby::Whitespace
" "
Symbol
:bodystmt
E 

  1) Error:
test select by a single klass(TraversalTest):
NoMethodError: private method `select' called for :bodystmt:Symbol

Fix:

# traversal.rb

        children.flatten.compact.inject(result) do |result, node| 
          return result if node.class.to_s == 'Symbol'
          result + node.select(*args, &block)
        end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment