Search code examples
rubyconstantsfreeze

Freeze arrays and hashes by default?


Just wondering if something like:

# frozen_string_literal: true

exists but for Array and Hash?

The goal is not having to .freeze every single of those within the same globals file.


Solution

  • Found a way to handle it without using another gem using only vscode and rubocop :

    1. Install the rubocop extension on vscode
    2. Open your .vscode/settings.json
    3. Append those rules :
    {
      "editor.formatOnSave": true,
      "editor.formatOnSaveTimeout": 5000,
      "ruby.format": "rubocop"
    }
    
    1. save
    2. enjoy

    Thanks to Tom Lord for the hint.