Searching for a method name is insufficient to know whether it is safe to delete it

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the ruby category.

Last Updated: 2021-05-16

I wanted to find all uses of the uk_law_author_search method:

class RecruitmentEmail
  def uk_law_author_search(user) end
end

So I searched my codebase for uk_law_author_search and got nothing. So is it safe to delete it? It would seem so...

But in fact, it turns out I was using the code... albeit dynamically with send

emailees.uniq.each do |user|
  recruitment_email_method = "#{country_code}_law_author_search"
  RecruitmentEmail.send(recruitment_email_method, user).deliver_later
end

Lessons

Any search for method usages in Ruby should also check for the class name in case the code uses send.

And for that reason, you should probably avoid calling send unless really justified.