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
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/sourcify/proc/methods/source_location.rb', line 5
def self.included(base)
base.class_eval do
if lambda{}.respond_to?(:source_location)
alias_method :__pre_sourcified_source_location, :source_location
def source_location(get_original = true)
if get_original
__pre_sourcified_source_location
elsif !@created_on_the_fly
__pre_sourcified_source_location
end
end
else
def source_location(get_original = true)
unless @created_on_the_fly
@source_location ||= (
file, line = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+).*?>$/.match(inspect)[1..2]
[file, line.to_i]
)
end
end
end
attr_writer :created_on_the_fly
[::Method, ::Symbol].each do |klass|
begin
klass.class_eval do
alias_method :__pre_sourcified_to_proc, :to_proc
def to_proc
(_proc = __pre_sourcified_to_proc).created_on_the_fly = true
_proc
end
end
rescue NameError
end
end
end
end
|