Skip to content

Files

Latest commit

 

History

History
30 lines (21 loc) · 605 Bytes

Style-ConstantVisibility.md

File metadata and controls

30 lines (21 loc) · 605 Bytes

Pattern: Missing explicit visibility for constant

Issue: -

Description

By default, Ruby makes all class and module constants public, which litters the public API of the class or module. Explicitly declaring a visibility makes intent more clear, and prevents outside actors from touching private state.

Examples

# bad
class Test
  BAR = 42
  BAZ = 43
end

# good
class Test
  BAR = 42
  private_constant :BAR

  BAZ = 43
  public_constant :BAZ
end

Further Reading