Coding Style Guide-Lines

File Naming

Files should be named after their contained modules/classes.

The following code would reside in the file thing/stuff.rb.

module Thing
  class Stuff
  
    ...

  end
end

Indentation

Two-space indentation for Ruby, XML, XSL, HTML and Javascript source-code. Tab indentation for other programming languages.

Strings

Use double-quotes when necessary, use single-quotes otherwise.

'i do not need double quotes here, so why use them?'
"I do need double quotes here, #{var}."

Embedded Strings

Use the %{ ... } syntax when embedding large strings into Ruby code

%{I find this style to be particularly clean.}

Defining Modules/Classes

Bad

class Bla::Ugly
  
  ...
  
end

Good

module Bla
  class Better
    
    ...
    
  end
end

Global Variables

Avoid using global variables, instead use class variables.

class Important
  
  def Important.data
    @@data ||= {}
  end
  
end

Blocks

Use &block syntax to explicitly receive and pass blocks.

def explicit_block(var,&block)
  ...
  compute(var,&block)
  ...
end

send

Always check if the requested method is public.

def bad_method_proxy(name)
  @obj.send(name)
end
def better_method_proxy(name)
  if @obj.public_methods.include?(name.to_s)
    return @obj.send(name)
  else
    return nil
  end
end