<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Selecting matching key/value pairs from a hash</title>
	<atom:link href="http://matthewbass.com/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewbass.com/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/</link>
	<description>Musings on software and life...</description>
	<lastBuildDate>Tue, 24 Aug 2010 16:33:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Matthew Bass</title>
		<link>http://matthewbass.com/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/comment-page-1/#comment-1975</link>
		<dc:creator>Matthew Bass</dc:creator>
		<pubDate>Tue, 06 Mar 2007 15:57:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.matthewbass.com/blog/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/#comment-1975</guid>
		<description>Mike sends in another example for us, one that doesn&#039;t copy the entire hash using &lt;code&gt;symbolize_keys&lt;/code&gt; first:

&lt;pre&gt;
class Hash
 def select_all(*attrs)
   reject { &#124;k, v&#124; !attrs.include?(k.to_sym) }
 end
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Mike sends in another example for us, one that doesn&#8217;t copy the entire hash using <code>symbolize_keys</code> first:</p>
<pre>
class Hash
 def select_all(*attrs)
   reject { |k, v| !attrs.include?(k.to_sym) }
 end
end
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew Bass</title>
		<link>http://matthewbass.com/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/comment-page-1/#comment-1973</link>
		<dc:creator>Matthew Bass</dc:creator>
		<pubDate>Tue, 06 Mar 2007 13:48:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.matthewbass.com/blog/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/#comment-1973</guid>
		<description>Pit e-mailed me directly with this alternate solution:

&lt;pre&gt;
def select_all(*attrs)
  (keys &amp; attrs).inject({}) { &#124;h, k&#124; h[k] = self[k] }
end
&lt;/pre&gt;

Not bad. He says that depending on the size of the hash and the number of attributes, this
implementation could be faster.</description>
		<content:encoded><![CDATA[<p>Pit e-mailed me directly with this alternate solution:</p>
<pre>
def select_all(*attrs)
  (keys &#038; attrs).inject({}) { |h, k| h[k] = self[k] }
end
</pre>
<p>Not bad. He says that depending on the size of the hash and the number of attributes, this<br />
implementation could be faster.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Austin Taylor</title>
		<link>http://matthewbass.com/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/comment-page-1/#comment-1970</link>
		<dc:creator>Austin Taylor</dc:creator>
		<pubDate>Tue, 06 Mar 2007 05:41:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.matthewbass.com/blog/2007/03/05/select-all-hash-keyvalue-pairs-matching-a-set-of-keys/#comment-1970</guid>
		<description>I would call it #select_keys, and I would glob lib/ in environment.rb.</description>
		<content:encoded><![CDATA[<p>I would call it #select_keys, and I would glob lib/ in environment.rb.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
