Ruby Parenthesis syntax exception with i++ ++i

后端 未结 3 669
野趣味
野趣味 2021-01-14 17:05

Why does this throw a syntax error? I would expect it to be the other way around...

>> foo = 5
>> foo = foo++ + ++foo                                     


        
3条回答
  •  Happy的楠姐
    2021-01-14 17:26

    Ruby does not have a ++operator. In your example it just adds the second foo, "consuming" one plus, and treats the other ones as unary + operators.

提交回复
热议问题