<?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:users1254</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1254" rel="self"/>
  <title>dive.myopenid.com</title>
  <updated>Tue Jun 23 12:23:30 -0700 2009</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor168018</id>
    <published>2009-06-23T12:23:30-07:00</published>
    <title>[Ruby] On shorten long variable names / beautify</title>
    <content type="html">&lt;p&gt;@Johannes, thx, but I think the cool thing about not breaking it up is that a grep or cmd+shift+f over the whole project is easier to read&lt;/p&gt;

&lt;p&gt;@Martin, ok, there's some hints ... like eg see if I really have to pass current_user.id or to have the helper check what kindof object it got and then extract what it needs ...&lt;/p&gt;

&lt;p&gt;more hints?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/929-shorten-long-variable-names-beautify/refactors/168018" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor167697</id>
    <published>2009-06-22T19:13:45-07:00</published>
    <title>[Ruby] On Is there better way to write following lines of code</title>
    <content type="html">&lt;p&gt;Also put your attention to your quoting / SQL injection!&lt;/p&gt;

&lt;p&gt;from &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html" target="_blank"&gt;http://api.rubyonrails.org/classes/ActiveRecord/Base.html&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;  class User &amp;lt; ActiveRecord::Base
    def self.authenticate_unsafely(user_name, password)
      find(:first, :conditions =&amp;gt; &amp;quot;user_name = '#{user_name}' AND password = '#{password}'&amp;quot;)
    end

    def self.authenticate_safely(user_name, password)
      find(:first, :conditions =&amp;gt; [ &amp;quot;user_name = ? AND password = ?&amp;quot;, user_name, password ])
    end

    def self.authenticate_safely_simply(user_name, password)
      find(:first, :conditions =&amp;gt; { :user_name =&amp;gt; user_name, :password =&amp;gt; password })
    end
  end
&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/882-is-there-better-way-to-write-following-lines-of-code/refactors/167697" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor167686</id>
    <published>2009-06-22T19:01:16-07:00</published>
    <title>[Ruby] On Decoding a json object while converting keys to symbols</title>
    <content type="html">&lt;p&gt;Adam is the man, once again :-)&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/908-decoding-a-json-object-while-converting-keys-to-symbols/refactors/167686" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor167673</id>
    <published>2009-06-22T18:59:20-07:00</published>
    <title>[Ruby] On Iterating An Array - Need to target 6th item for no margin</title>
    <content type="html">&lt;p&gt;maybe have something like&lt;/p&gt;

&lt;p&gt;= render first block 5 times, iterate from 0 to 5
&lt;br /&gt;= render last and special case&lt;/p&gt;

&lt;p&gt;leaving you with 2 lines, instead of 6 or 1,
&lt;br /&gt;so that the two cases are easy to distinguish visually?&lt;/p&gt;

&lt;p&gt;I just don't like too much logic in one line ...&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/911-iterating-an-array-need-to-target-6th-item-for-no-margin/refactors/167673" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code929</id>
    <published>2009-06-22T18:52:10-07:00</published>
    <updated>2009-06-23T15:27:14-07:00</updated>
    <title>[Ruby] shorten long variable names / beautify</title>
    <content type="html">&lt;p&gt;I wonder how you make a line like this more readable. &lt;/p&gt;

&lt;p&gt;I mean it is quite readable, only it is a bit long, and lines like this break in the editor, so it's actually not very readable ... do you worry about things like this? how would you make this more beautiful?&lt;/p&gt;

&lt;p&gt;(actually I already made a useless variable definition &amp;quot;nextmyvocabulary&amp;quot;, just to shorten the redirect_to)&lt;/p&gt;

&lt;pre&gt;def upgrade_and_restart
  @myvocabulary.upgrade
  nextmyvocabulary = Myvocabulary.draw(current_user.id, params[:position], @myvocabulary.vocabulary.lesson.proficiency.id)
  redirect_to myvocabulary_url(nextmyvocabulary, :position =&amp;gt; params[:position])
end&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/929-shorten-long-variable-names-beautify" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor144193</id>
    <published>2009-01-22T14:13:00-08:00</published>
    <title>[Ruby] On While loop to get unique value</title>
    <content type="html">&lt;p&gt;nice nice nice thank you all! :-) uhm the magic 8 ... it's a variable to define the length of the vouchercode. but hm since it's always the 8 i coulda remove it ... good point!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/697-while-loop-to-get-unique-value/refactors/144193" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code697</id>
    <published>2009-01-06T16:44:48-08:00</published>
    <updated>2009-02-12T13:34:08-08:00</updated>
    <title>[Ruby] While loop to get unique value</title>
    <content type="html">&lt;p&gt;Coming from python, I would say this is pretty straight forward. But knowing some ruby, I suspect there's a DRYer way, right?&lt;/p&gt;

&lt;pre&gt;def before_create_save(record)
  vouchercode = generate_vouchercode(8)
  while Voucher.find(:first, :conditions =&amp;gt; {:vouchercode =&amp;gt; vouchercode})
    vouchercode = generate_vouchercode(8)
  end
  record.vouchercode = vouchercode
end&lt;/pre&gt;</content>
    <author>
      <name>dive.myopenid.com</name>
      <email>alfonsgrabher@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/697-while-loop-to-get-unique-value" rel="alternate"/>
  </entry>
</feed>

