# Eval defaulting to binding

**URL:** <https://www.ruby-forum.com/t/eval-defaulting-to-binding/82408>\
**Category:** Ruby\
**Created:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/eval-defaulting-to-binding/82408 "2007-01-19T16:30:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/eval-defaulting-to-binding/82408/1 "2007-01-19T16:30:14Z")

</div>

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 🙂

kind regards -botp

---

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/eval-defaulting-to-binding/82408/2 "2007-01-19T16:31:09Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [September 25, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/eval-defaulting-to-binding/82408/3 "2007-09-25T22:46:01Z")

</div>

From: Robert K. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] :

# 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

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