Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby style question : blocks or inheritance?

I have some classes that will do something based on some conditions . The conditions are sent as parameters to some methods . My questions is related to ruby coding style :

  • should the conditions be sent as lambdas/blocks , or as some objects that inherit from a condition class ?

  • which is more efficient in terms of OOP ?

Thanks !

like image 716
Geo Avatar asked Dec 09 '22 22:12

Geo


1 Answers

I don't know which is more efficient from an execution time perspective, but blocks are more efficient from a user interface perspective. The person using your method just writes the condition in a block instead of having to define a whole new class, create an instance, and pass it to your method.

like image 54
Andru Luvisi Avatar answered Jan 02 '23 09:01

Andru Luvisi