LoginSignup
0
0

More than 3 years have passed since last update.

nodemonとrufoでRubyスクリプトを効率的に開発するための設定

Last updated at Posted at 2019-08-07

メモです。

nodemonでRubyスクリプトをホットリロードしつつ、
rufoで綺麗にフォーマットかけながら開発するための設定について記載しています。

nodemonのインストール

nodemonをインストールするためには、npmが必要になります。
npmはNode.jsをインストールすると使えるようになります。

npm install -g nodemon

rufoのインストール

自動フォーマットのためにrufoをインストールする。
Ruby2.4.5以上が必要だったのでバージョン確認しておきます。

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

$ gem install rufo

VSCodeにExtensionをインストール

VSCodeにMarketplaceからRufo - Ruby formatterをインストールします。

動作確認

# スクリプトの変更をnodemonで監視実行できるように起動しておく。
# ふつうにruby index.rbでもよい。
$ nodemon index.rb

以下のように汚い感じでスクリプトをつくります。

index.rb
def world
puts "hello"
  end


        world
    world
world

上の状態で保存すると、綺麗にフォーマットされます。

index.rb
def world
  puts "hello"
end

world
world
world

このときのnodemonを立ち上げているコンソールは以下のようになっています。
エディタで保存するたびに、再実行されます。

[nodemon] clean exit - waiting for changes before restart
[nodemon] restarting due to changes...
[nodemon] starting `ruby test.rb`
hello
hello
hello

おわり。

0
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
0
0