Last active
May 22, 2019 13:48
-
-
Save pirj/4ee52b5f5d8557ec58488aac45559297 to your computer and use it in GitHub Desktop.
NodePattern debug boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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