7

I tried creating a model called "class" (as in a graduating class of students), and encountered all kinds of problems. What are some other words or class names to avoid in Rails?

Some links I've found:
http://juicebar.wordpress.com/2007/05/30/reserved-words-in-rails/
http://railsforum.com/viewtopic.php?id=22242

GeekJock
  • 11,066
  • 13
  • 43
  • 44

3 Answers3

6

This page has a very long list of words not to use:

https://reservedwords.herokuapp.com/words

Because 'class' comes up very commonly as a name with metaprogamming, I think the accepted ruby alternative is 'klass'. This is obviously a different context from your graduating class situation, but maybe still helpful.

Angela
  • 3,050
  • 2
  • 30
  • 37
  • 2
    doesn't work anymore. just links to [link]http://h4dev.com/entries?search=reserved+keyword+don%27t+use which is also nothing. – afxjzs Jan 03 '12 at 23:24
  • 1
    The linked page can now be found at http://oldwiki.rubyonrails.org/rails/pages/ReservedWords – Ryan Muller Jul 16 '12 at 18:20
  • 1
    This site seems very useful for reserved word checking: https://reservedwords.herokuapp.com/words – d3vkit Jun 24 '15 at 23:52
3

You've got most of them there. Obviously, you also need to avoid the Ruby keywords:

alias   and     BEGIN   begin   break   case    class   def     defined  
do      else    elsif   END     end     ensure  false   for     if  
in      module  next    nil     not     or      redo    rescue  retry  
return  self    super   then    true    undef   unless  until   when  
while   yield  

(from http://www.zenspider.com/Languages/Ruby/QuickRef.html#4).

Also, don't name a model Transaction (but the generator warns about that!).

Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
1

Class is a built-in ruby class. It is what classes is an instance of.

class Foo
end

puts Foo.class
# => Class

Overriding that blows up the entire object structure in Ruby.

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111