gpt4 book ai didi

ruby-on-rails - Ruby on Rails : . 常量化 : wrong constant name error?

转载 作者:数据小太阳 更新时间:2023-10-29 07:13:55 29 4
gpt4 key购买 nike

我正在使用这个:

4.times { |i| assert_not_equal("content#{i + 2}".constantize, object.first_content) }

我之前声明过局部变量

content1
content2
content3
content4
content5

我得到的错误

NameError: wrong constant name content2

这个错误是什么意思?我很确定我想要 content2 =\

最佳答案

你必须用一个大字母来调用 ruby​​ 常量:

Content2 而不是 content2

A constant name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. By convention, constant variables are normally spelled using uppercase letters and underscores throughout.

Link

需要注意的是,没有常量变量,只有常量值。

关于ruby-on-rails - Ruby on Rails : . 常量化 : wrong constant name error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6429956/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com