LoginSignup
0
0

More than 5 years have passed since last update.

【Ruby】メソッドの戻り値ってなんだ<2>

Last updated at Posted at 2018-06-24

Rubyの戻り値について追加演習

サイコロ2つコロコロして、合計が7以上なら次に進めますよ、7未満ならゲームオーバーよ、のシーンを切り出します。

#def メソッド名でメソッドを定義
def over_sum?(higher)
#return 値で値(higher >= 7)を返す
  return higher >= 7
#defメソッドはここでおしまい
end

#if文の条件式で、メソッドを呼び出す
if over_sum?(11)
#(ここに入れた数字)次第で結果が分かれる
  puts "next challenge!!"

else
  puts "gameover"

end

これ使い方合ってるのかなあ

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