<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rel=me &#187; set_trace_func</title>
	<atom:link href="http://rel.me/t/set_trace_func/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Wed, 01 Feb 2012 07:26:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>set_trace_func and filter on regex</title>
		<link>http://rel.me/2007/08/29/trace-with-regex/</link>
		<comments>http://rel.me/2007/08/29/trace-with-regex/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 00:58:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[set_trace_func]]></category>

		<guid isPermaLink="false">/2007/09/03/trace-with-regex</guid>
		<description><![CDATA[I needed to use the trace_func to figure out a bug, and I came up with: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 class Tracer class &#60;&#60; self def on(io = STDERR, [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to use the trace_func to figure out a bug, and I came up with:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt>29<tt>
</tt><strong>30</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">class</span> <span class="cl">Tracer</span><tt>
</tt>    <tt>
</tt>    <span class="r">class</span> &lt;&lt; <span class="cl">self</span><tt>
</tt>      <tt>
</tt>      <span class="r">def</span> <span class="fu">on</span>(io = <span class="co">STDERR</span>, regex = <span class="pc">nil</span>)<tt>
</tt>        set_trace_func proc { |event, file, line, id, binding, classname|<tt>
</tt>          <span class="r">if</span> !regex.blank?<tt>
</tt>            s = format(<span class="s"><span class="dl">&quot;</span><span class="k">%8s %s:%-2d %10s %8s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>, event, file, line, id, classname)<tt>
</tt>            io.printf(s) <span class="r">if</span> s =~ regex            <tt>
</tt>          <span class="r">else</span><tt>
</tt>            io.printf(<span class="s"><span class="dl">&quot;</span><span class="k">%8s %s:%-2d %10s %8s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>, event, file, line, id, classname)<tt>
</tt>          <span class="r">end</span><tt>
</tt>        }<tt>
</tt>      <span class="r">end</span><tt>
</tt>    <tt>
</tt>      <span class="r">def</span> <span class="fu">off</span><tt>
</tt>        set_trace_func <span class="pc">nil</span><tt>
</tt>      <span class="r">end</span><tt>
</tt>    <tt>
</tt>      <span class="r">def</span> <span class="fu">trace</span>(io = <span class="co">STDERR</span>, regex = <span class="pc">nil</span>, &amp;block)<tt>
</tt>        on(io, regex)<tt>
</tt>        retval = <span class="r">yield</span> <span class="r">if</span> block_given?<tt>
</tt>        off      <tt>
</tt>        retval<tt>
</tt>      <span class="r">end</span><tt>
</tt>      <tt>
</tt>    <span class="r">end</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Then <tt>Tracer.trace { 1 + 1 }</tt> or specify a regex filter:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Tracer</span>.trace(<span class="co">STDERR</span>, <span class="rx"><span class="dl">/</span><span class="k">Fixnum</span><span class="dl">/</span></span>) { <span class="i">1</span> + <span class="i">1</span> }<tt>
</tt>  c-call (irb):<span class="i">2</span>           +   <span class="co">Fixnum</span><tt>
</tt>c-<span class="r">return</span> (irb):<span class="i">2</span>           +   <span class="co">Fixnum</span><tt>
</tt>=&gt; <span class="i">2</span><tt>
</tt>&gt;&gt; </pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/08/29/trace-with-regex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

