Sha256: 62ffc56bafcefef550a650b3310c65c05134d4c5bc5a42b24c75d3888f5d7abc

Contents?: true

Size: 670 Bytes

Versions: 2

Compression:

Stored size: 670 Bytes

Contents

require 'rubygems'
require File.dirname(__FILE__) + '/../lib/sexp_path'
require 'parse_tree'

path = ARGV.shift
if !path
  puts "Prints classes and methods in a file"
  puts "usage:"
  puts "  ruby print_methods.rb <path>"
  exit
end

code = File.read(path)
sexp = Sexp.from_array(ParseTree.new.parse_tree_for_string(code, path))

class_query = Q?{ s(:class, atom % 'class_name', _, _) }
method_query = Q?{ s(:defn, atom % 'method_name', _ ) }

results = sexp / class_query / method_query

puts path
puts "-" * 80

results.each do |sexp_result|
  class_name = sexp_result['class_name']
  method_name = sexp_result['method_name']
  puts "#{class_name}##{method_name}"
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
adamsanderson-sexp_path-0.4.0 examples/print_methods.rb
sexp_path-0.4.0 examples/print_methods.rb