1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ruby-mode のファイル保存時にファイルの先頭に `# frozen_string_literal: true` を挿入する

Posted at

以下を init.el かなんかに書く。

init.el
(defun ruby-mode-set-frozen-string-literal-true ()
  (when (eq major-mode 'ruby-mode)
    (save-excursion
      (widen)
      (goto-char (point-min))
      (unless (looking-at "^# frozen_string_literal: true")
        (insert "# frozen_string_literal: true\n\n")))))

(add-hook 'ruby-mode-hook (lambda()
                            (add-hook 'before-save-hook 'ruby-mode-set-frozen-string-literal-true)))

カスタマイズすれば frozen_string_literal 以外にもいろいろできそう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?