Code Monkey home page Code Monkey logo

upperline-hs-ruby-style-guide's Introduction

Ruby Style Guide

When you're coding, it's easy to write your methods and classes without giving much thought to how the code actually looks in the file. But, being mindful of how you lay out the code - where you put your indentations, parentheses, hard returns, etc. - makes your code much more readable. That'll make you and the coders you work with much happier down the road because it'll be much easier to understand what is happening in your code. Here are a few style pointers...

Defining Methods

Let's start with defining methods. When you define a method, you use the def keyword, and follow it with the name of the method, right? Well, if your method takes an argument, please put your parentheses exactly after the method name. Don't put a space in between; directly plug in the parentheses.

Something like this should do:

def my_method(argument1)
end

The first letter of a method is always lowercased, unless you're writing a class because classes are cooler than methods. Class names are always capitalized. In method names, snake_case_is_best_practice. If your method name needs to be more than one word, do something like this:

def more_than_one_word
end

Instead of something like this, which is not snake cased:

def morethanoneword
end

or even worse:

def MORETHANONEWORD
end

###Defining Classes On the other hand, class names are Capitalized and CamelCased. That means that if you're using multiple words to name your class, push them right up against eachother and capitalize each new word. Your class would look like this:

class MyAwesomeClass
end

Two Space Indentations

Lastly, please indent with two spaces inside of a class, amethod, an if statement, a for loop, or anything else that transcends one line.

if "flat" + "iron" == "flatiron"
  puts "yay!"
end

Wrap Up

Why do you need to follow these simple style rules when writing your Ruby code? You need to be mindful of other programmers. If you ever ask for help and your code is just completely ugly, you'll be making it much harder for the person helping you. Or when you're working at a tech company and you're assigned a partner to build a program with... if your part of the code is completely ugly, it'll be much harder to maintain consistency and clarity.

So don't be selfish, follow these simple rules and thank me later.

View Ruby Style Guide on Learn.co and start learning to code for free.

upperline-hs-ruby-style-guide's People

Contributors

dfenjves avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.