In Ruby, foo.inspect can print out all instance variables — can we print out an individual one if there is no accessor?

前端 未结 2 1028
醉梦人生
醉梦人生 2021-01-19 17:04

Often, we can use p foo or foo.inspect to see the instance variables, but is it only the default behavior and the object can choose to show somethi

2条回答
  •  不知归路
    2021-01-19 17:39

    In Ruby, all access protection can be circumvented using reflection:

    @bar.instance_variable_get(:@wah)
    

提交回复
热议问题