View ruby-styleguide.md

Ruby Style Guide

This style guide is based on this community style guide.

Most of the rules listed will have a brief explanation to understand the reasoning behind each. If none is provided, maybe it's too obvious, or assume that its main purpose is to improve readability.

All new projects must adhere to this style guide. Existing and ongoing projects should stick with their current conventions or they can adapt this if no convention is being followed yet.

General

View 9605.rb
prefixes = [
:generic_uncommon, :missing_information, :closed_account, :incorrect_information, :insufficient_funds, :not_authorized
]
['', '_follow_up', '_suspended'].each do |suffix|
prefixes.each do |prefix|
method = "#{prefix}#{suffix}"
FailedBillingMailer.send(method, Company.full_service.active.last).deliver
end
end
We couldn’t find that file to show.
View pacman-singleton-usage.rb
# move up the singleton instance
Pacman.instance.move_up
# the same instance will move right
Pacman.instance.move_right
# the same instance will move down
Pacman.instance.move_down
View pacman-singleton.rb
class Pacman
def self.get_instance
# instantiate the singleton instance if it is not existing yet.
if @instance.nil?
@instance = Pacman.new
end
@instance
end
View rhcc-correct-password-function.rb
def correct_password? user, password
encrypted_password = BCrypt::Password.new password
user.encrypted_password == encrypted_password
end
View rhcc-email-format-function.rb
VALID_EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
def valid_email? email
email =~ VALID_EMAIL_REGEX
end
View rhcc-correct-password.rb
encrypted_password = BCrypt::Password.new password
if user.encrypted_password == encrypted_password
View rhcc-email-format.rb
email !=~ /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i