Skip to content

Commit ee8de1f

Browse files
committed
Another way to get all local vars. Fixes RUBY-16930.
Works with SImpleDelegator
1 parent 52ad000 commit ee8de1f

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

lib/debase/context.rb

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
module Debase
22
class Context
33
def frame_locals(frame_no=0)
4-
result = {}
5-
binding = frame_binding(frame_no)
6-
locals = eval("local_variables", binding)
7-
if locals.respond_to?(:each)
8-
locals.each do |local|
9-
result[local.to_s] = safe_eval(local.to_s, binding)
10-
end
11-
else
12-
result[locals.to_s] = safe_eval(locals.to_s, binding)
13-
end
14-
result
4+
frame_binding(frame_no).eval('local_variables.inject({}){|h, v| h[v.to_s] = eval(v.to_s); h}')
5+
rescue => e
6+
{'debase-debug' => "*Evaluation error: '#{e}'" }
157
end
168

179
def frame_class(frame_no=0)
@@ -46,16 +38,5 @@ def at_line(file, line)
4638
def at_return(file, line)
4739
handler.at_return(self, file, line)
4840
end
49-
50-
private
51-
52-
def safe_eval(expr, binding)
53-
begin
54-
eval(expr, binding)
55-
rescue => e
56-
"*Evaluation error: '#{e}'"
57-
end
58-
end
59-
6041
end
6142
end

0 commit comments

Comments
 (0)