#11 Refactoring User Name Part 2

Testing and refactoring go hand in hand. Refactoring is all about improving code without changing its behavior. Testing is all about making sure you don't change the behavior while you are improving the code.


# models/user.rb
def full_name
  [first_name, middle_initial_with_period, last_name].compact.join(' ')
end

def middle_initial_with_period
  "#{middle_initial}." unless middle_initial.blank?
end


你可能感兴趣的:(Go)