Open5
【VSCode環境構築】Rubyに一から入門してみる

作業場所

Dockerfile & Dev Container
ベースイメージ
- 安定のdebian slimで
Dockerfile
- 必要なパッケージが分からないので最小限
- 必要に応じて拡張
VSCode Dev Container
- あとで
.vscode/extensions
をこっちに移しておく - (
devcontainer.json
から.vscode/extensions
読み込めたら嬉しいんだけどね)

LSPなど
ruby-lsp
- Shopify製らしい
-
gem "ruby-lsp"
を入れたら動いた
https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp
debuggerの構成

Formatter
RubyわからないのでStandard
を使う
選択肢A. Rubocop
- デファクトなlinter & formatterっぽい
選択肢B. Standard
-
rubocop
上で動作する設定不要のlinter & formatter -
ruby-lsp
が自動で読み込んでくれるらしい (CodeActionが動作する)
If you don't see your preferred editor above, Standard Ruby also offers robust language server support, in two ways, both included with the standard gem:
- A Ruby LSP add-on, which (if the standard gem is in your Gemfile) will be loaded automatically

Rake
- Ruby DSLで書けるmakeみたいなビルドツール
-
Rakefile
にコマンドを登録する
Standardを実行
-
Rakefile
に追記 -
rake standard
,rake standard:fix
,rake standard:fix_unsafely
とかで実行できる
require "standard/rake"
npmスクリプトを実行
-
rake format
を登録
task :format do
sh "npm run format"
end
最終形
- 面倒なのでstandardはshで実行
-
rake -T
で登録されているコマンドを確認できる