Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
Does dynamic dispatching decrease the cyclomatic complexity?

Imagine the following method converting a boolean into an int:

def bool_to_int(bool)
  bool ? 1 : 0
end

bool_to_int(false) # => 0
bool_to_int(true) # => 1

Because of the conditional, the cyclomatic complexity score is two. Does the score drop to one by utilizing refinements in Ruby?:

module Extension
  refine FalseClass do
    def to_int; 0; end
  end

  refine TrueClass do
    def to_int; 1 end
  end
end

using Extension

false.to_int # => 0
true.to_int # => 1

In other words; does dynamic dispatching reduce the cyclomatic complexity score or are we just hiding the complexity by letting Ruby do the “heavy lifting”?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Cyclomatic complexity is based on the nodes and edges available in them. By implementing dynamic dispatching, you are just implementing conditions in a different way.

So, the cyclomatic complexity stays constant.

Edit based on the below comments.

Yes, the cyclomatic concept is bound tightly with conditional statements. Reducing if/else statements results in less cyclomatic complexity. But the paths are constants. But now they are more isolated and not based on the conditions.

So I feel, the answer should be, Yes, the complexity gets reduced if you are successful in removing the conditional statements. But paths are constants.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda