Conventions: Coding Style

Coding Style

This style is used in the standard library. You can use it in your own project to make it familiar to other developers.

Naming

Type names are camelcased. For example:

class ParseError < Exception
end

module HTTP
  class RequestHandler
  end
end

alias NumericValue = Float32 | Float64 | Int32 | Int64

lib LibYAML
end

struct TagDirective
end

enum Time::DayOfWeek
end

Method names are underscore-cased. For example:

class Person
  def first_name
  end

  def date_of_birth
  end

  def homepage_url
  end
end

Variable names are underscore-cased. For example:

class Greeting
  @@default_greeting = "Hello world"

  def initialize(@custom_greeting = nil)
  end

  def print_greeting
    greeting = @custom_greeting || @@default_greeting
    puts greeting