Tell, Don't Ask

I don’t see how your code accomplishes this. It’s still got a conditional, and you’re not using polymorphism.

I also don’t think the alias_method calls or use of modules are very clear.

The call is a personal preference. It allows my classes to match the lambda interface.

And you are of course, correct that I didn’t actually skip the conditional. However due to the opinionated nature of my object method names, you can easy do this with a send.

thanks for calling me out. i cheated here :slight_smile:

Do you have an example? Can you somehow get rid of the conditional altogether with your approach? I don’t see how this is possible, but would love to be proven false.

I have a practical example of how I used polymorphism to completely remove conditionals from a Minimax algorithm I implemented for my Tic-tac-toe project. See code here: xo/minimax.rb at 098b231796cdb417809fa3977b169bca8c81c546 · dwayne/xo · GitHub. Let me know if you need help understanding the code. I will gladly explain later, it’s just that I’m pressed for time right now. Hope I helped.

So if the tell don’t ask principle tells us that we should not query an object internal and take actions based on that, ActiveRecord conditional validations are a violation of that, right?
For example:

class SshUser
  validates_presence_of :ssh_key, if: :admin?
end

I don’t think that’s a violation because that’s within the same class. You can ask questions about your own instance data as much as you like.