Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Last active June 28, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/f29cc56e8f0ec71ff5d735340a493841 to your computer and use it in GitHub Desktop.
Save tenderlove/f29cc56e8f0ec71ff5d735340a493841 to your computer and use it in GitHub Desktop.
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