Ruby Source Code Layout

- 1 min
# bad - four spaces
def some_method
    do_something
end

# good
def some_method
  do_something
end
# bad
puts 'foobar'; # superflous semicolon

puts 'foo'; puts 'bar' # two expressions on the same line

# good
puts 'foobar'

puts 'foo'
puts 'bar'

puts 'foo', 'bar' # this applies to puts in particular
# bad
class FooErro < StandError
end

# okish
class FooError < StandardError; end

# good
FooError = Class.new(StandardError)
# bad
1 .. 3
'a' ... 'z'

# good
1..3
'a'...'z'
# bad - It has two empty lines.
some_method


some_method

# good
some_method

some_method

Learn More.

Nurul Fajar

Nurul Fajar

Mahasiswa banyak acara

comments powered by Disqus
rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora