public
Description: Code smell detector for Ruby
Home | Edit | New

Getting Started

First, make sure you have Ruby and ruby gems; then see the Installation page to get a copy of Reek. Now let’s put it to work!

Imagine you have a source file called csv_writer.rb with the following contents:

class CsvWriter
  def write_line(fields)
    if (fields.length == 0)
      puts
    else
      write_field(fields[0])
      1.upto(fields.length-1) do |i|
        print ","
        write_field(fields[i])
      end
      puts
    end
  end

  #...
end

Now point Reek at the file to get a smell report:

$ reek csv_writer.rb
CsvWriter#write_line calls fields.length multiple times (Duplication)
CsvWriter#write_line has approx 6 statements (Long Method)
CsvWriter#write_line/block has the variable name 'i' (Uncommunicative Name)

That’s it — you’re up and running with Reek!

(Note that Reek isn’t yet able to see all of the problems with your code. So for example it can’t see that the CsvWriter#write_line method is both formatting and outputting the CSV strings — or indeed that the CsvWriter class similarly has more than one responsibility.)

Next you’ll probably want to explore Reek’s Command-Line Options and Configuration Files, or take a look at Reek-Driven Development.

Last edited by kevinrutherford, Sat Sep 12 13:11:25 -0700 2009
Home | Edit | New
Versions: