<?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>Coffee Powered &#187; blocks</title>
	<atom:link href="http://www.coffeepowered.net/tag/blocks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coffeepowered.net</link>
	<description>code and content</description>
	<lastBuildDate>Mon, 09 Jan 2012 18:32:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Quick tip &#8211; use anonymous blocks!</title>
		<link>http://www.coffeepowered.net/2008/10/09/quick-tip-use-anonymous-blocks/</link>
		<comments>http://www.coffeepowered.net/2008/10/09/quick-tip-use-anonymous-blocks/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 05:30:21 +0000</pubDate>
		<dc:creator>Chris Heald</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blocks]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.coffeepowered.net/?p=75</guid>
		<description><![CDATA[In tracking down a memory leak in one of our Rails apps today, I ran across an interesting post detailing the difference between anonymous and named blocks in Ruby, and the performance differences therein. It&#8217;s definitely worth a look, especially if you&#8217;re running in a complex environment, where new closures will be large and unwieldy. [...]]]></description>
			<content:encoded><![CDATA[<p>In tracking down a memory leak in one of our Rails apps today, I ran across an <a href="http://blog.pluron.com/2008/02/rails-faster-as.html">interesting post</a> detailing the difference between anonymous and named blocks in Ruby, and the performance differences therein.</p>
<p>It&#8217;s definitely worth a look, especially if you&#8217;re running in a complex environment, where new closures will be large and unwieldy. It&#8217;s very easy, too. Any time you use:</p>
<pre class="brush: ruby; title: ; notranslate">
def note(text, options = {}, &amp;block)
  options[:class] = ((options[:class] || &quot;&quot;) + &quot; form-note&quot;).strip
  content_tag(:div, text, options, &amp;block)
end
</pre>
<p>Instead, don&#8217;t explicitly name the block parameter; just yield to it, and you prevent all the messiness of creating a new Proc object.</p>
<pre class="brush: ruby; title: ; notranslate">
def note(text, options = {})
  options[:class] = ((options[:class] || &quot;&quot;) + &quot; form-note&quot;).strip
  content_tag(:div, text, options) {|*block_args| yield(*block_args) if block_given? }
end
</pre>
<p>I don&#8217;t have benchmarks just yet, but anecdotally it has definitely slowed instance memory consumption in my apps. It&#8217;s worth taking a look at!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coffeepowered.net/2008/10/09/quick-tip-use-anonymous-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

