Why am I getting objects printed twice?

前端 未结 4 1548
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 08:53

When I am in irb or in rails and I create some iteration with each, I am getting the whole struct printed again in my terminal or inside the browser. Example:

4条回答
  •  失恋的感觉
    2020-11-27 09:11

    You see them printed twice: once as side effect, second time as the return value. irb always puts the last return value. The return value for each is its receiver. You cannot avoid that when using irb, but they will not show up when you run the script as standalone software. The First 1, ..., 4 are the outputs of your puts. They are called side effects.

提交回复
热议问题