Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 732 Bytes

replace-inline-code-with-function-call.md

File metadata and controls

33 lines (24 loc) · 732 Bytes

Replace Inline Code With Function Call

Replace a chunk of code with a call to a method that does the same thing. Often, you can find a standard library function that does what you need.

This is one of the most valuable refactorings, because it makes code more expressive and readable and reduces the total amount of code in the codebase!

Example

Before

names_string = ""
names.each_with_index do |name, index|
  names_string << name
  if index < names.length - 1
    names_string << ", "
  end
end

After

names_string = names.join(", ")

References