Coding as a Craft
  • Introduction
    • Learning objectives
  • Your first website
  • ATM Challenge - Ruby basics
    • Step 1
    • Step 2
    • Step 3
    • Step 4
    • Step 5
    • Step 6
    • Step 7
    • Step 8
    • Step 9
    • Step 10
  • Library challenge - Advanced Ruby
    • Important topics
  • Javascript Introduction
    • Variables, objects and arrays
    • Comparisons and Manipulations
    • Javascript Sample Problems
    • Defining Functions
    • Prototypes & Classes
    • Miscellaneous
  • BMI Challenge - JavaScript basics
    • Jasmine - Set up
    • First tests
    • The calculator
    • The Document-Object Model
    • Web interface
    • Acceptance tests
    • Moving on
  • Fizz Buzz in JavaScript
    • NodeJS
  • Checkout challenge
  • Open Weather Challenge
  • SlowFood challenge - OO & TDD
    • Step 1 - Setting up the project
    • Step 2 - Focus on the user experience
    • Step 3 - Entity Relationship Diagrams
    • Step 4 - Implementing the core features
    • Step 5 - Working with the database
    • Step 6 - Working with BDD
    • Extra - Setting up RSpec & Cucumber
  • Ruby On Rails introduction
  • Static Website with Middleman
    • Week lab
    • Setup Middleman
    • HAML - HTML abstraction markup language
    • SASS
    • Accessing data
    • Partials
    • Deploy to Github pages
  • BDD with Rails
    • Exercise - Implement extra features
  • Rails Messaging
    • Working with Legacy Code
    • Tips and Tricks
  • Mid Course Project
    • Project Schedule
  • Going mobile with Ionic
    • Setup
    • Javascript Modules
    • Introduction to Angular
    • Getting to Know Ionic - BMI Challenge
    • Ionic unit and e2e testing
  • The Cooper test challenge
    • The logic
    • The Back-end
    • The Client
    • Connecting the dots
    • Saving and retrieving data
    • Display charts
    • Wrapping up
    • Results tables
  • News Room Challenge
    • Main features
    • Design Sprint
    • Pivotal Tracker
    • Guides
      • i18n with Ruby on Rails
      • Rails 5.2 Scaffold
      • Attachments with Active Storage
      • Encrypted Credentials in Rails 5.2
      • Role-Based Authorization
      • Rendering JSON objects in Rails
      • Testing Ionic Applications
  • SlowFood API - API first or second?
  • Extras
    • Naming Standards
    • Classes vs Modules
    • Code structure
    • Bower
    • Code Review Instructions
    • About README's
    • MVC
    • Three-Tier Architecture
    • Rails Scaffold
    • Tailwind css with Rails
  • Career
    • General Personality
    • Agile Mindset
    • Basic Ruby
    • Advanced Ruby
    • Databases
    • SOLID Principles
  • Sinatra & SlowFood
    • Sinatra - an introduction
    • Start small
    • More Hello World
  • Ember
    • Hello World
Powered by GitBook
On this page
  • Classes and Modules
  • Methods
  • Variables
  1. Extras

Naming Standards

You are free to set your own class and methods names.

Classes and Modules

Class and Module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Withdraval, class AccountHolder.

Methods

When naming methods the goal is to be descriptive but short. Name based on what it will return or what the major intended side effect will be. You shouldn't be missing any parts from the name because the method should only do one thing anyway. If you can't tell what the method will return based on the name, you probably need a better name. If your method name seems insanely long, your method may be trying to do more than one thing. End with a question mark ? if it will return true/false.

Method names should begin with a lowercase letter (or an underscore). Apart from letters, only ?, ! and = characters are allowed as method name suffixes. This is a list of suggestions on naming standards for different kind of methods:

  • Methods that do something should be verbs:

    • obj.calculate

    • obj.set_name

    • obj.get_date

  • Methods that are accessors (or behave like them) should be nouns:

    • foo = obj.name

    • obj.date

    • obj.order_total

  • Interrogative methods (if the

    method returns true/false) get phrased as questions:

    • obj.date_today?

    • obj.name?

    • obj.calculation_done?

  • Methods that modify the object itself, should be

    exclamations:

    • obj.truncate_body!

    • obj.remove_name!

Variables

Variables in Ruby can contain data of any type. You can use variables in your Ruby programs without any declarations. Variable name itself denotes its scope (local, global, instance, class.).

  • A local variable (declared within an object) name consists of a lowercase letter (or an underscore) followed by name characters (balance, cyrrent_collection).

  • An instance variable name starts with an @ sign followed by a name (@sign, @name, etc).

  • A class variable name start with a double @ sign (@@) and may be followed by digits, underscores, and letters, e.g. @@colour

  • Global variables starts with a dollar ($) sign followed by other characters, e.g. $global

PreviousExtrasNextClasses vs Modules

Last updated 7 years ago