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] コンソールから入力を受け取る

Last updated at Posted at 2020-06-17

Progate学習メモ

gets.chompを使う

.rb
puts "名前を入力してください"

# コンソールから入力を受け取り、変数nameに代入する
name = gets.chomp
puts "こんにちは、#{name}さん"

コンソール↓

名前を入力してください # 入力待機状態になってる

「太郎」と入力すると、

こんにちは、太郎さん

gets.chompは文字列で受け取るので、数値で受け取りたい場合は、
count = gets.chomp.to_iというようにする。


参考
Progate

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?