<?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:users58</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/58" rel="self"/>
  <title>Frahugo</title>
  <updated>Fri Aug 14 13:04:27 -0700 2009</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor257184</id>
    <published>2009-08-14T13:04:27-07:00</published>
    <title>[Ruby] On loop a random generator until a criteria is met</title>
    <content type="html">&lt;p&gt;You can simply use the until statement.  Just make sure to test for nil value.&lt;/p&gt;

&lt;pre&gt;def create_something(min_value)
  something = SomeClass.generate_random until something &amp;amp;&amp;amp; something.some_attribute &amp;lt; min_value
end&lt;/pre&gt;</content>
    <author>
      <name>Frahugo</name>
      <email>hugo@cekoya.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/992-loop-a-random-generator-until-a-criteria-is-met/refactors/257184" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor388</id>
    <published>2007-10-12T01:13:45-07:00</published>
    <title>[Ruby] On Iffy</title>
    <content type="html">&lt;p&gt;I'm using a Globalite plugin.  I love it because it is a simple way to achieve what Marc-Andr&#195;&#169; just suggested.  You install the plug-in, put your localized strings in Yaml files, set the current language in your controller and voila.  You then the l() method on a symbol.  The localized strings are read once and cached in memory (you havae to restart the server if you modify the files, but in production mode, we want that to avoid always reading files).&lt;/p&gt;

&lt;pre&gt;## lang/ui/fr.yml [yaml]
point: proximite
nopoint: dans
happy: Nous adorons tous Ruby on Rails

## lang/ui/en.yml [yaml]
point: near
nopoint: in
happy: We all love Ruby on Rails

## Controller [ruby]
Globalite.language = self.lang.to_sym   # This could be in a before_filter in application.rb
key = self.location_type.to_sym
breaker = key.l( :nopoint.l )           # If no key found for location_type, defaults to key :nopoint
&lt;/pre&gt;</content>
    <author>
      <name>Frahugo</name>
      <email>hugo@cekoya.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/75-iffy/refactors/388" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor118</id>
    <published>2007-09-29T08:00:23-07:00</published>
    <title>[Ruby] On Arrow Code</title>
    <content type="html">&lt;p&gt;I usually don't like to have multiple return point in a method since if might complicate maintenance.  But when it is a very small method (which it should be), I allow me to put more than one return point.  &lt;/p&gt;

&lt;p&gt;So here's how I would do it... easy to read... easy to maintain.&lt;/p&gt;

&lt;pre&gt;def parse_line2
  return skip_line unless line_is_parsable?
  return @line_stack.pop unless line_is_nested?
  return parse_attribute if line_is_attribute?

  # do parsing
  # ...
end
&lt;/pre&gt;</content>
    <author>
      <name>Frahugo</name>
      <email>hugo@cekoya.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/17-arrow-code/refactors/118" rel="alternate"/>
  </entry>
</feed>

