Styling In Ruby

Ruby Got Style! Say ‘Whaaaa’!!!

One thing I struggle with and am continuously working on is how my code looks. Esthetics definitely has a different meaning for me now. LOL. I’m not cleansing someones face anymore but rather cleaning up the code by fixing whitespace or making sure I indented correctly. On a serious note though nice clean code can allow other programmers to do their job efficiently.

Snake Case

Photo by Mohan Moolepetlu on Unsplash

lower case words separated by underscore

  • method names
  • variable assignments
  • 1 indentation(tab) is two spaces.

Camel Case

Photo by Oskars Sylwan on Unsplash
  • Class Names ex. ApplicationController -class definition starts with a capital letter in Ruby.
  • No Space

Check out more information google “ruby style guide”. Get familiar with Ruby Styling. You can practice in REPL.it.

A Few Things To Avoid

Photo by geissht on Unsplash
  • trailing whitespace

Other Tips

  • do not use ; to terminate expressions and/or statements
  • Use one expression per line
puts "hello"
puts "goodbye"
  • Use spaces around commas, colons, semicolons and operators.
sum = 2 * 5
a, b = 2, 5
class HayError < StandardError; end

There are a few that do not require that extra space like:

  • exponent operators **
  • slash in rational literals /
  • navigation operators &.

There are many more styling rules when it comes to multi-lines, if else statements, loops, assignments and much more. Thank goodness for access to resources readily available to us from google. It’s the little things.

#KeepCoding #CodingEsty #CodingLife

Refer to rubystyle.guide

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store