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

前端 未结 5 1896
暗喜
暗喜 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条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-28 20:23

    Because both $string and s are references to the same object, the string "String". However, when you assign s to 1, you don't change the object "String", you make it reference a new object.

提交回复
热议问题