<?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:users1695</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1695" rel="self"/>
  <title>ReinH</title>
  <updated>Wed Sep 09 18:35:16 -0700 2009</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor302865</id>
    <published>2009-09-09T18:35:16-07:00</published>
    <title>[Ruby] On Hash assignment</title>
    <content type="html">&lt;p&gt;One option is to make a factory Hash. More a design alternative than a strict refactoring.&lt;/p&gt;

&lt;pre&gt;@subscriptions = Hash.new {|h,k| h[k] = SubscriptionType.make(k)}
&lt;/pre&gt;</content>
    <author>
      <name>ReinH</name>
      <email>reinh@reinh.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/981-hash-assignment/refactors/302865" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor302835</id>
    <published>2009-09-09T18:11:52-07:00</published>
    <title>[Ruby] On [Ruby] Iterating...</title>
    <content type="html">&lt;p&gt;I'm not sure that this can be significantly refactored. Ruby doesn't have a circular linked list class. #each is not equivalent in behavior. Here's the only thing I can see to refator:&lt;/p&gt;

&lt;pre&gt;def self.get_next
  @i += 1
  @i = 0 if @i &amp;gt;= CONT.length # fix bug where @i == CONT.length
  CONT[@i]
end
&lt;/pre&gt;</content>
    <author>
      <name>ReinH</name>
      <email>reinh@reinh.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/988-ruby-iterating/refactors/302835" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor302825</id>
    <published>2009-09-09T17:54:41-07:00</published>
    <title>[Ruby] On Call a function to each member</title>
    <content type="html">&lt;p&gt;&amp;amp; is not a unary method. It's a sigil that instructs the interpreter to treat the following variable as a block, similar to the * sigil for array expansion.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>ReinH</name>
      <email>reinh@reinh.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1027-call-a-function-to-each-member/refactors/302825" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor302812</id>
    <published>2009-09-09T17:41:19-07:00</published>
    <title>[Ruby] On Button code creates a generic, styled input button.</title>
    <content type="html">&lt;p&gt;This code has issues in the HTML it generates (input tags are self-closing and do not have content, window.location= is an ugly hack), but nevertheless refactored for science. Assignment of onclick_event is buggy in original implementation (branches where the variable is undefined), has been fixed in refactor. Also used more intention revealing variable names.&lt;/p&gt;

&lt;pre&gt;def button(title, values)
  values[:type] ||= &amp;quot;button&amp;quot;
  values[:category] ||= &amp;quot;primary&amp;quot;

  onclick_event = values[:url] ? &amp;quot;window.location=#{values[:url]}&amp;quot; : values[:onclick]
  endcap = content_tag(:div, '&amp;amp;nbsp', :class =&amp;gt; 'endcap')

  inline_icon = &amp;quot;&amp;quot;
  if values[:category]  =~ /secure|prev|next/
    inline_icon = content_tag(:img, '', :src =&amp;gt; &amp;quot;../images/#{$&amp;amp;}.gif&amp;quot;)
  end
      
  content_tag(:div, :class =&amp;gt; &amp;quot;button button_&amp;quot; + values[:category]) do
    content_tag(:input, inline_icon + endcap,
      :value =&amp;gt; title,
      :type =&amp;gt; values[:type],
      :onclick =&amp;gt; onclick_event,
      :class =&amp;gt; values[:class],
      :id =&amp;gt; values[:id]
    )
  end
end&lt;/pre&gt;</content>
    <author>
      <name>ReinH</name>
      <email>reinh@reinh.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1029-button-code-creates-a-generic-styled-input-button/refactors/302812" rel="alternate"/>
  </entry>
</feed>

