<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users801</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/801" rel="self"/>
  <title>rjspotter</title>
  <updated>Wed Aug 06 22:01:54 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14588</id>
    <published>2008-08-06T22:01:54-07:00</published>
    <title>[Ruby] On Find the Intersection of Arrays with a Hash</title>
    <content type="html">&lt;p&gt;I'm basicly golfing at this point but it was a fun exersize&lt;/p&gt;

&lt;pre&gt;pools = {1 =&amp;gt; [1,2,3], 2=&amp;gt; [3,4,5], 3=&amp;gt; [5,6,7]}

pools.inject([]) {|m,x| m &amp;lt;&amp;lt; x[1].select {|y| pools[x[0] + 1].include?(y) unless pools[x[0] + 1].nil?}}.flatten

#or

pools.inject([]) {|m,x| m &amp;lt;&amp;lt; (x[1] &amp;amp; pools[x[0] + 1] unless pools[x[0] + 1].nil?)}.compact.flatten&lt;/pre&gt;</content>
    <author>
      <name>rjspotter</name>
      <email>rjspotter@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/413-find-the-intersection-of-arrays-with-a-hash/refactors/14588" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14585</id>
    <published>2008-08-06T19:54:26-07:00</published>
    <title>[Ruby] On Array#split_with(something)</title>
    <content type="html">&lt;p&gt;Yeah like that.  *head-desk*
&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>rjspotter</name>
      <email>rjspotter@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/423-array-split_with-something/refactors/14585" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14584</id>
    <published>2008-08-06T19:45:28-07:00</published>
    <title>[Ruby] On link_to with an image_tag and text</title>
    <content type="html">&lt;p&gt;alternate suggestion&lt;/p&gt;

&lt;pre&gt;&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;
  a.go_back { background: url(/images/go_back.png) center left no-repeat; padding-left: /*width of go_back.png*/;}
&amp;lt;/style&amp;gt;

&amp;lt;%= link_to 'Go Back', user_path(@user), :class =&amp;gt; 'go_back' %&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>rjspotter</name>
      <email>rjspotter@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/419-link_to-with-an-image_tag-and-text/refactors/14584" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14582</id>
    <published>2008-08-06T19:31:20-07:00</published>
    <title>[Ruby] On link_to with an image_tag and text</title>
    <content type="html">

&lt;pre&gt;&amp;lt;%= link_to &amp;quot;#{image_tag(&amp;quot;go_back.png&amp;quot;)}Go Back&amp;quot;, user_path(@user) %&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>rjspotter</name>
      <email>rjspotter@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/419-link_to-with-an-image_tag-and-text/refactors/14582" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code423</id>
    <published>2008-08-06T19:07:41-07:00</published>
    <updated>2008-08-06T19:54:27-07:00</updated>
    <title>[Ruby] Array#split_with(something)</title>
    <content type="html">&lt;p&gt;This started out as &amp;quot;wouldn't it be cool if I could split an array into two arrays based on a regexp match?&amp;quot;  The rest may be .... something not very useful.&lt;/p&gt;

&lt;pre&gt;require 'rubygems'
require 'functor'

class Array

=begin
usage:
  matches, non-matches = arr.split_with exp # where [Regexp, Proc, Array, Integer].include? exp  
=end
  def split_with(exp = nil, &amp;amp;block)
    @_split_with_functor ||= Functor.new do
      given(Regexp, Array) {|exp, arr| arr.select {|x| x =~ exp}}
      given(Proc, Array) {|exp, arr| arr.select {|x| exp.call(x)}}
      given(Array, Array) {|exp, arr| arr.select {|x| exp.include?(x)}}
      given(Integer, Array) {|exp, arr| arr.select {|x| x.to_i &amp;lt; exp}}
    end
    matches = @_split_with_functor.call(exp || block,self)
    [matches, self - matches]
  end

end
&lt;/pre&gt;</content>
    <author>
      <name>rjspotter</name>
      <email>rjspotter@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/423-array-split_with-something" rel="alternate"/>
  </entry>
</feed>

