Skip to content

Instantly share code, notes, and snippets.

@pirj
Last active May 22, 2019 13:48
Show Gist options
  • Save pirj/4ee52b5f5d8557ec58488aac45559297 to your computer and use it in GitHub Desktop.
Save pirj/4ee52b5f5d8557ec58488aac45559297 to your computer and use it in GitHub Desktop.
NodePattern debug boilerplate
def match(pattern, source)
ruby_version = RUBY_VERSION.to_f
node_pattern = RuboCop::NodePattern.new(pattern)
ast = RuboCop::ProcessedSource.new(source, ruby_version).ast
node_pattern.match(ast)
end
match('(send nil? :sum $...)', 'sum(1,2,3,n)')
# => [s(:int, 1), s(:int, 2), s(:int, 3), s(:send, nil, :n)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment