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”?