LoginSignup
0
0

More than 1 year has passed since last update.

Ruby | ループ内での評価はメソッドの戻り値にはならない

Last updated at Posted at 2016-06-09
def example
  3.times do
    false
  end 
end
example # => 3

なんとなく false が返りそうな気がしてしまうが。

この場合は 3.times の戻り値が、そのまま example メソッドの戻り値になる。
なぜなら 3.times もメソッドなので、example メソッドの中で最後に評価されるのは、その戻り値だからだ。

環境

  • ruby 2.3.1

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

0
0
5

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