Last active
June 28, 2019 18:02
-
-
Save tenderlove/f29cc56e8f0ec71ff5d735340a493841 to your computer and use it in GitHub Desktop.
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
require "ast" | |
class Superduper | |
class EnumerableAST | |
include Enumerable | |
def initialize ast | |
@ast = ast | |
end | |
def each &block | |
enumerate @ast, &block | |
end | |
private | |
def enumerate node, &block | |
yield node | |
node.children.grep(RubyVM::AbstractSyntaxTree::Node).each do |node| | |
enumerate node, &block | |
end | |
end | |
end | |
def self.parse_file file | |
enum = EnumerableAST.new RubyVM::AbstractSyntaxTree.parse_file file | |
enum.each { |node| | |
if node.type == :DEFN || node.type == :DEFS | |
method = node | |
if method.children.last.type == :SCOPE && | |
method.children.last.children.last && | |
method.children.last.children.last.type == :ZSUPER | |
puts "#{file}:#{method.first_lineno}" | |
end | |
end | |
} | |
end | |
end | |
if $0 == __FILE__ | |
Superduper.parse_file(ARGV[0] || __FILE__) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment