Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Traversal error on Module #3

Open
kristianmandrup opened this Issue · 0 comments

1 participant

@kristianmandrup
Collaborator
  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
Something went wrong with that request. Please try again.