Rails Reserved Class Names

青春壹個敷衍的年華 提交于 2019-12-05 05:34:46

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.

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!).

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!