5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/sourcify/proc/methods/to_source.rb', line 5
def self.included(base)
base.class_eval do
ref_proc = lambda {}
if ref_proc.respond_to?(:to_source)
alias_method :__pre_sourcified_to_source, :to_source
def to_source(opts = {}, &body_matcher)
flag = opts[:strip_enclosure]
(@sourcified_sources ||= {})[flag] ||=
flag ? Ruby2Ruby.new.process(to_sexp(opts, &body_matcher)) : __pre_sourcified_to_source
end
elsif ref_proc.respond_to?(:to_ruby)
def to_source(opts = {}, &body_matcher)
flag = opts[:strip_enclosure]
(@sourcified_sources ||= {})[flag] ||=
flag ? Ruby2Ruby.new.process(to_sexp(opts, &body_matcher)) : to_ruby
end
else
Sourcify.require_rb('proc', 'parser')
def to_source(opts = {}, &body_matcher)
(@sourcified_parser ||= Parser.new(self)).
source(opts.merge(:body_matcher => body_matcher))
end
end
end
end
|