符号在 Rails 项目中必须是唯一的吗?

Must symbol be unique in Rails project?

当我们在 Rails 中使用符号时(例如:用户,:类型...),它们在项目中必须是唯一的吗?例如,我们可以将状态(在状态机中)命名为与属性相同的名称吗?还是有碰撞的风险?

Symbol objects represent names and some strings inside the Ruby interpreter. They are generated using the :name and :"string" literals syntax, and by the various to_sym methods. The same Symbol object will be created for a given name or string for the duration of a program's execution, regardless of the context or meaning of that name.

回答你的问题:没有碰撞的风险。