Zum Inhalt springen

Mutable Global State (ARCH6187)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key ruby.quality.mutable-global-state · Severity warning · Category quality

Global variables and mutable class variables (@@) create hidden dependencies and race conditions, making it impossible to track who mutates the state.

class Counter
@@count = 0
def self.increment
@@count += 1
end
end
class Counter
def initialize
@count = 0
end
def increment
@count += 1
end
end

Replace shared mutable state with instance state, or move it into an injected, encapsulated object.