This document outlines 10 commandments for Ruby programmers. The commandments include avoiding coupling domain objects with frameworks, not stealing and pasting code, avoiding nil, not using if/else statements, not mocking in tests, not taking tests in vain, refactoring daily, pairing with other programmers, challenging oneself, and avoiding bad practices. The document is presented by Emilio Gutter, a Ruby programmer and founder of 10Pines, sharing his expertise and experience.
2. I AM EMILIO A RUBY PROGRAMMER
Software developer +15 yrs
10Pines founder
Agiles community founding member
agiles 2012 conference co-chair
husband, father and homeBrewer
3. I. Thou shalt have no
domain objects coupled
with thy frameworks
4. class Speaker < ActiveRecord::Base
!
devise :omniauthable,
:omniauth_providers => [:facebook]
!
def approve_session(session)
# do something
SessionMailer.approve(speaker: self,
session: session).deliver
end
!
end
6. public List selectPending(List registrations) {
!
List pending = new ArrayList();
for (Registration registration: registrations) {
if (!registration.isPaid()) {
pending.add(registration);
}
}
return pending;
}
8. class SessionsController < ApplicationController
!
def create
!
@session = Session.new(session_params)
!
if @session.save
redirect_to my_sessions_path,
notice: 'Session created successfully'
else
render :new
end
!
end
end
9. class Program
!
def find_by_author(author)
!
sessions = Session.where(author: author,
approved: true)
!
if sessions.empty?
# do something
else
# do something
end
end
!
end
11. class AttendeePresenter
!
def phone_number
!
unless self.address.nil?
unless self.address.phone_number.nil?
self.address.phone_number
else
'Phone number not present'
end
else
'Address not present'
end
end
!
end
12. class Attendee
def initialize(address)
if address.nil?
raise ArgumentError, 'Address is required'
end
@address = address
end
!
def address
@address || UnknownAddress.new
end
!
def phone_number
Optional.new(@address).
within {|address| address.phone_number}
end
end
14. class BankAccount
!
def process a_transaction
!
if a_transaction.type == :purchase
# charge transaction fee
else
# assume refund
end
end
!
end
15. class BankAccount
!
def process a_transaction
a_transaction.process self
end
!
def process_purchase a_transaction
# charge transaction fee
end
!
def process_refund a_transaction
# refund transaction fee
end
!
end
16. class Purchase < Transaction
!
def process a_payment_method
a_payment_method.process_purchase self
end
end
!
class Refund < Transaction
!
def process a_payment_method
a_payment_method.process_refund self
end
end