<?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: Picking values from Ruby hashes</title>
	<atom:link href="http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/</link>
	<description>Musings on software and life...</description>
	<lastBuildDate>Sun, 11 Jul 2010 16:07:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: John Long</title>
		<link>http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/comment-page-1/#comment-16209</link>
		<dc:creator>John Long</dc:creator>
		<pubDate>Fri, 27 Jun 2008 03:47:13 +0000</pubDate>
		<guid isPermaLink="false">http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/#comment-16209</guid>
		<description>How about:

&lt;code&gt;
class Hash
  def pick(*values)
    pairs = select { &#124;k,v&#124; values.include?(k) }
    Hash[*pairs.flatten]
  end
end

hash.pick(:foo, :bar)
#returns  {:bar=&gt;&quot;baz&quot;, :foo=&gt;&quot;bar&quot;}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>How about:</p>
<p><code><br />
class Hash<br />
  def pick(*values)<br />
    pairs = select { |k,v| values.include?(k) }<br />
    Hash[*pairs.flatten]<br />
  end<br />
end</p>
<p>hash.pick(:foo, :bar)<br />
#returns  {:bar=&gt;"baz", :foo=&gt;"bar"}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: neerajdotname</title>
		<link>http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/comment-page-1/#comment-16208</link>
		<dc:creator>neerajdotname</dc:creator>
		<pubDate>Thu, 26 Jun 2008 20:51:54 +0000</pubDate>
		<guid isPermaLink="false">http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/#comment-16208</guid>
		<description>You can use facets Hash method slice.

h.slice(:foo,:bar) #=&gt; another hash

h.slice(:foo,:bar).to_a #=&gt; to convert the hash into array.

http://facets.rubyforge.org/doc/index.html</description>
		<content:encoded><![CDATA[<p>You can use facets Hash method slice.</p>
<p>h.slice(:foo,:bar) #=&gt; another hash</p>
<p>h.slice(:foo,:bar).to_a #=&gt; to convert the hash into array.</p>
<p><a href="http://facets.rubyforge.org/doc/index.html" rel="nofollow">http://facets.rubyforge.org/doc/index.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Moonen</title>
		<link>http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/comment-page-1/#comment-16207</link>
		<dc:creator>Scott Moonen</dc:creator>
		<pubDate>Thu, 26 Jun 2008 19:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://matthewbass.com/2008/06/26/picking-values-from-ruby-hashes/#comment-16207</guid>
		<description>If you&#039;re using Rails, then ActiveSupport::CoreExtensions::Hash::Slice provides a slice() method to slice a hash, and this is automatically added to the Hash class for you.  Its usage is exactly as given above, except that it returns a hash instead of an array of pairs.</description>
		<content:encoded><![CDATA[<p>If you&#8217;re using Rails, then ActiveSupport::CoreExtensions::Hash::Slice provides a slice() method to slice a hash, and this is automatically added to the Hash class for you.  Its usage is exactly as given above, except that it returns a hash instead of an array of pairs.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
