Eval defaulting to binding

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=‘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 :slight_smile:

kind regards -botp

On 12.01.2007 10:59, Peña wrote:

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 :slight_smile:

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

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

Kind regards

robert

From: Robert K. [mailto:[email protected]] :

class Object

def debug

md = caller[0].match /\A(.+):(\d+):confused: || [nil, “unknown”,

“unknown”]

puts "FILE: #{md[1]} LINE: #{md[2]}, ID: #{object_id}, OBJECT:

#{inspect}"

end

end

robert, as always, thanks for the tip.
kind regards -botp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs