Ruby on Rails: .constantize: incorrect constant name error?

I use this:

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

and I previously declared local variables

content1
content2
content3
content4
content5

the error i get

NameError: wrong constant name content2

Whot means this error? I'm sure I want content2 = \

+5
source share
2 answers

You need to call the ruby ​​constants with a capital letter:

Content2instead of Content2.

The name of the constant begins with a capital letter, followed by the characters of the name. Class names and module names are constants and follow constant naming conventions. By convention, constant variables are usually written in capital letters and underscores.

Link

It should be noted that there are no such variables as constant, but constant values.

+6

eval ( "content # {i + 2}" )

, eval , : -)

0

All Articles