Mutable Global State (ARCH6187)
Esta página aún no está disponible en tu idioma.
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.
Incorrect
Section titled “Incorrect”class Counter @@count = 0
def self.increment @@count += 1 endendCorrect
Section titled “Correct”class Counter def initialize @count = 0 end
def increment @count += 1 endendReplace shared mutable state with instance state, or move it into an injected, encapsulated object.