Class: Method

Inherits:
Object
  • Object
show all
Defined in:
lib/parse_tree_extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_rubyObject



24
25
26
27
# File 'lib/parse_tree_extensions.rb', line 24

def to_ruby
  sexp = self.to_sexp
  Ruby2Ruby.new.process sexp
end

#to_sexpObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/parse_tree_extensions.rb', line 13

def to_sexp
  require 'parse_tree'
  require 'unified_ruby'
  parser = ParseTree.new(false)
  unifier = Unifier.new
  with_class_and_method_name do |klass, method|
    old_sexp = parser.parse_tree_for_method(klass, method)
    unifier.process(old_sexp)
  end
end

#with_class_and_method_nameObject



2
3
4
5
6
7
8
9
10
11
# File 'lib/parse_tree_extensions.rb', line 2

def with_class_and_method_name
  if self.inspect =~ /<Method: (.*)\#(.*)>/ then
    klass = eval $1
    method  = $2.intern
    raise "Couldn't determine class from #{self.inspect}" if klass.nil?
    return yield(klass, method)
  else
    raise "Can't parse signature: #{self.inspect}"
  end
end