Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using this:

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

and i have previously declared local variables

content1
content2
content3
content4
content5

the error I get

NameError: wrong constant name content2

Whot does this error mean? I'm pretty sure that I want content2 =\

like image 722
NullVoxPopuli Avatar asked Jun 21 '11 18:06

NullVoxPopuli


1 Answers

You have to call ruby constants with a big letter:

Content2 instead of 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

It should be noted though that there is no such thing as constant variables, but constant values.

like image 117
Yet Another Geek Avatar answered Nov 20 '22 02:11

Yet Another Geek