module Pentest::RubyParser

Public Class Methods

get_sexp(method) click to toggle source

Get S-expression of specified method. Return nil if something went wrong.

# File lib/pentest/ruby_parser.rb, line 7
def get_sexp(method)
  file, loc = method.source_location
  ast = ::RubyParser.new.parse File.read(file), file
  ast.each do |exp|
    next unless Sexp === exp
    next unless exp[0] == :defn
    if exp.line == loc
      return exp
    end
  end
  nil
end