Why doesn't this work if in Ruby everything is an Object?

前端 未结 5 1885
暗喜
暗喜 2020-12-28 20:11

Considering that in the Ruby programming language everything is said to be an Object, I safely assumed that passing arguments to methods are done by reference. Howe

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 20:38

    Ruby passes values around to functions, and these values are references to objects. In your function you are reassigning s to another value, in this case a reference to 1. It does not modify the original object.

    Your method isn't changing the object passed in, you're changing what s refers to.

提交回复
热议问题