eval defaulting to binding

P

Peña, Botp

Hi,

sometimes (or many times), i put some debugging lines in my code. =
something like,

C:\family\ruby>cat -n debugger.rb
1 #-----------------
2 # debugger.rb
3 #-----------------
4
5 DEBUG_MACRO_1=3D'puts "FILE: #{__FILE__} LINE: #{__LINE__}, ID: =
#{[self
to_s, self.object_id]}"'
6
7 def debugger bin
8 eval(DEBUG_MACRO_1,bin)
9 end

C:\family\ruby>cat -n test5.rb
1 #------------
2 # test5.rb
3 #------------
4
5 require 'debugger.rb'
6
7 class A
8 def a
9 debugger binding #<-- this is my debugging line
10 end
11 end
12
13 A.new.a

C:\family\ruby>ruby test5.rb
FILE: test5.rb LINE: 9, ID: #<A:0x28804bc>21234270

I'd like to pass the "binding" argument as default on the debugger line, =
so that i do not have to state it; ie, just "debugger" instead of =
"debugger binding". Is that possible? tips, pls :)

kind regards -botp
 
R

Robert Klemme

I'd like to pass the "binding" argument as default on the debugger line, so that i do not have to state it; ie, just "debugger" instead of "debugger binding". Is that possible? tips, pls :)

No, but there is no need for eval here. This is as good:

class Object
def debug
md = caller[0].match /\A(.+):(\d+):/ || [nil, "unknown", "unknown"]
puts "FILE: #{md[1]} LINE: #{md[2]}, ID: #{object_id}, OBJECT:
#{inspect}"
end
end

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top