Hi --

On Mon, 30 Jan 2006, Dirk Meijer wrote:

> hi all,
> i was wondering if my rubyness has increased above the 'total
> newbie'-level..
> so below is some code in my coding style, can you give comments on how it
> looks and how effective it is.

Traditional Ruby indentation is two spaces.  One space is a bit of a
squeeze :-)

When it comes to stylistic things, my favorite source of information
is the standard library.  You can learn a lot by grepping around.

> def find_factors( number )

The space after the opening parenthesis is rare:

1.8$ grep "( " `find . -name "*.rb"` | wc -l
     1641
1.8$ grep "(" `find . -name "*.rb"` | wc -l
    37951

(and if you filter out 'rexml' and 'yaml' it drops to 544 :-)

> factors = []
> 1.upto( number ) do | factor |

The space after the first | is non-existent in the standard library:

1.8$ grep "do |" `find . -name "*.rb"` | wc -l
     1153
1.8$ grep "{|" `find . -name "*.rb"` | wc -l
     1512
1.8$ grep "do | " `find . -name "*.rb"` | wc -l
        0
1.8$ grep "{| " `find . -name "*.rb"` | wc -l
        0
1.8$ grep "{ | " `find . -name "*.rb"` | wc -l
        0


David

-- 
David A. Black
dblack / wobblini.net

"Ruby for Rails", from Manning Publications, coming May 1, 2006!
http://www.manning.com/books/black