<?xml version='1.0' encoding='UTF-8'?>
<elementos_gw>
  <documento>
    <id>965</id>
    <autor>5</autor>
    <nome>My Ruby coding style</nome>
    <nome_facil>my ruby coding style</nome_facil>
    <criacao>2011-03-18 18:02:26</criacao>
    <alteracao>2011-03-23 21:04:35</alteracao>
    <texto>- 2 spaces (not tab) identations;

- use {{{||}}}, {{{&amp;&amp;}}}, {{{!}}} instead of {{{or}}}, {{{and}}} and {{{not}}}

- use {{{unless}}} instead of {{{if !}}}

- use {{{until}}} instead of {{{while !}}}

- use {{{dup}}} instead of {{{clone}}}

- use {{{yield}}} instead of Procs

- use {{{alias_method}}} instead of {{{alias}}} ([http://stackoverflow.com/questions/4763121/ruby-should-i-use-alias-or-alias-method Motivation])

- in method calls, avoid parenthesis whenever possible.
Exceptions:
  1. before block: {{{meth(args) { code } }}} instead of {{{meth args { code } }}}
  2. as param: {{{meth1 arg1, arg2, meth2(argX, argY, argZ)}}} instead of {{{meth1 arg1, arg2, meth2 argX, argY, argZ}}}
  3. around expressions: {{{meth(a ? b : c)}}} instead of {{{meth a ? b : c}}}
  4. before method chaining: {{{meth1(a).meth2}}} instead of {{{meth1 a.meth2}}}
  5. after super: {{{super(a, b, c)}}} instead of {{{super a, b, c}}}

- use symbols instead of strings whenever possible (in case of immutable strings), specially in hash keys. Use to_s when necessary

- in default parameteres, use {{{nil}}} instead of {{{&#039;&#039;}}}. Example: {{{def fn astring = nil}}}. Use to_s when necessary. Motivation: {{{if astring}}} is better than {{{unless astring.empty?}}}.

- within defs, duplicate arguments to avoid then be overwritten.
Example:
{{{
class X
  def fn a
    # uses a copy of a
    a = a.dup

    # modifies a with no worries
    a.delete.format.kill.zerofill.add(rand(42)).scramble
  end
end

a = &#039;hihaha&#039;
X.new.fn a
puts a           #=&gt; &#039;hihaha&#039;
}}}

Stay tuned with precedences! They rules the exceptions.

- if you do the right way, you avoid unnecessary remarks to explain the exceptions.</texto>
    <publico>1</publico>
    <original>0</original>
    <anterior>0</anterior>
    <versao>0</versao>
    <traducao>0</traducao>
    <propriedade>
      <nome>language</nome>
      <valor>english</valor>
      <publico>1</publico>
    </propriedade>
    <propriedade>
      <nome>assunto</nome>
      <valor>ruby</valor>
      <publico>1</publico>
    </propriedade>
  </documento>
</elementos_gw>
