Skip to content

Instantly share code, notes, and snippets.

View r4mbo7's full-sized avatar
馃
https://gitlab.com/cdlr75

De La Roche Constantin r4mbo7

馃
https://gitlab.com/cdlr75
View GitHub Profile
@r4mbo7
r4mbo7 / cyclomatic.rb
Created June 19, 2026 08:30
Cyclomatic complexity analyzer for Ruby methods.
#!/usr/bin/env ruby
# Cyclomatic complexity analyzer for Ruby methods.
#
# Counts the number of linearly independent paths through a method by
# starting at 1 and adding 1 for each decision point:
# - conditionals : if, elsif, unless (including postfix forms), ternary ?:
# - loops : while, until, for (including postfix forms)
# - case/rescue : each `when` clause, each `rescue` clause
# - boolean ops : &&, ||, and, or
# - safe nav : &. (each call may short-circuit, so it's a branch)