What is the difference between “if” statements with “then” at the end?

前端 未结 5 1217
一向
一向 2020-12-03 04:27

What\'s the difference between these two Ruby if statements when we put a then at the end of the if statement?

if(val          


        
5条回答
  •  庸人自扰
    2020-12-03 04:44

    The then is only required if you want to write the if expression on one line:

    if val == "hi" then something.meth("hello")
    else something.meth("right")
    end
    

    That brackets in your example are not significant, you can skip them in either case.

    See the Pickaxe Book for details.

提交回复
热议问题