Ruby関係の記事で、WindowsでRuby開発できるようにしたから日付が立ってしまいましたが、とりあえずHelloWorldを書いていきましょう。
目次
ファイルの作成
新規ファイル作成
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image.png?resize=430%2C226&ssl=1)
[File] - [New File]と選択します。
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-1.png?resize=401%2C268&ssl=1)
これで、新しいファイルが開きました。
ファイルの保存
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-2.png?resize=446%2C327&ssl=1)
[File] - [Save]を選択します。
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-3.png?resize=946%2C533&ssl=1)
ファイル保存のウィンドウが表示されるので、好きな保存場所を指定します。
ファイル名は画像では「Hello.rb」としています。
ファイルの種類はRubyを選びます。
保存先とファイル名の指定ができたら、「保存」をクリックします。
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-4.png?resize=339%2C212&ssl=1)
ファイルが保存されてVSCodeの画面上にRubyのファイルとして表示されるようになりました。
文字列の表示
ソースコードの記載
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-5.png?resize=345%2C202&ssl=1)
図のようにprint "Hello World"
と記載します。
ファイルの保存
[File] - [Save]を選択するか、Ctrl + s を押してファイルを保存します。
ターミナルの表示
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-6.png?resize=490%2C538&ssl=1)
[View] - [Terminal]を選択します。
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-8.png?resize=1024%2C768&ssl=1)
VSCodeの下半分にターミナルの画面が表示されます。
今回の例ではDドライブの下にtestフォルダを作成して、その中にRubyのファイルを入れたので、ターミナルからコマンドを使用してRubyのファイルがある場所に移動します。cd d:\test
を実行してください。
プログラムの実行
![](https://i0.wp.com/inuisou.com/wp-content/uploads/2019/09/image-9.png?resize=588%2C267&ssl=1)
Rubyコマンドを使用してプログラムを実行します。
ターミナル上でRuby Hello.rb
と打ち込んでEnterを押してください。
実行結果の「Hello World」が表示されました。