> > def trace_(&b)
> > 	file,line_nr=caller()[0].split(':')
> > 	line_nr=line_nr.to_i
> > 	linecnt=1
> > 	expr=nil
> > 	File.open(file).each_line do |line|
> > 		if linecnt==line_nr
> > 			if line =~ /(^|\W)trace_\s*{\s*(.*?)\s*}/
> > 				expr = $2
> > 			end
> > 			break
> > 		end
> > 		linecnt+=1
> > 	end
> > 	if expr
> > 		puts "#{expr}: #{eval(expr, b).inspect}"
> > 	end
> > end
> 
> Why not just 'yield' to get the value of the block in this case? I
> don't think the 'eval' is needed.

Because I didn't think, only copied ;). You are right.

One could also not use a block, only parens, and let the function receive
the evaluated expression (we get the literal expression from the source
file). Ie:

def trace_(x)
	...
	... (change the regexp to match \( \) instead of { } )
	...
	if expr
		puts "#{expr}: #{x.inspect}"
	end
end

but I think a block and a yield is better, because one could put it between
begin..rescue, or decide not to evaluate it, etc...