Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 561 Bytes

inline-method.md

File metadata and controls

30 lines (21 loc) · 561 Bytes

Inline Method

Remove a method declaration, copying the code in the method's body to its callsites.

Example

Before

def greeting(name)
  "Hello, " + name
end

puts greeting "World"

After

puts "Hello, " + "World"

Next Steps

After you inline a method, sometimes you end up with constants that can be combined (as in the example above, in which we're performing the computation "Hello, " + "World" with hardcoded constants). A good follow-up refactoring is Compile Constant Value [BC].