0
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 2017-10-25

rubyで、自作メソッドを作って
そのメソッドにキーボード入力で値を入れて
戻り値を取得してみます。

test.rb
def test(num1, num2)
  puts "合計:#{ num1 + num2 }"
end

input1 = gets.chomp.to_i
input2 = gets.chomp.to_i
test(input1, input2)

test.rbをターミナルで実行して
戻り値が返ってくるか確かめてみます。

test.rb
$ ruby test.rb
#=> 111 # 入力値をinputに代入
#=> 444 # 入力値をinput1に代入
#=> 合計:555 メソッドの戻り値

こんな感じでメソッドを作って実行してみました。
これは初心者の初歩的なものです。

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?