klzmkg
Last Updated: October 29, 2016
·
72
· neutralino1
981494 10151466984546915 1613396205 o

Conditional method call pattern

In Ruby, and other languages, we often do this

def perform
   perform_action
end

def perform_action
   if should_perfom_action?
      action.perform
   end
end

def should_perform_action?
   # conditions
end

I find that it is more explicit and correct to follow this practice instead:

def perform
   perform_action if should_perform_action?
end

def perform_action
   action.perform
end

def should_perform_action?
   # conditions
end
Say Thanks
Respond