Why are symbols in Ruby not thought of as a type of variable?

前端 未结 8 1546
臣服心动
臣服心动 2020-11-30 12:50

New to programming and to Ruby, and I hope this question about symbols is in line. I understand that symbols in Ruby (e.g., :book, :price) are usef

8条回答
  •  天涯浪人
    2020-11-30 13:29

    They aren't variables because they don't hold values, they are immutable. The thing is the value itself. It's similar to numbers. You can't set the value of 1. 1 = 2 doesn't work.

提交回复
热议问题