Uninitialized Constant错误是常规NameError异常类的变体。 它有几个原因。 当代码引用它找不到的类或模块时,您会看到此错误,通常是因为代码不包含require,它指示Ruby文件加载类。 在Ruby中,变量/方法以小写字母开头,而类以大写字母开头。 如果代码没有反映出这种区别,您将收到未初始化的常量异常。NameError错误的另一个可能原因是你在代码中犯了一个简单的拼写错误。Ruby区分大小写,因此“TestCode”和“Testcode”完全不同。 该代码包含rubygems的提及,除了旧版本的Ruby之外,所有这些都被弃用。


The Uninitialized Constant error is a variation of the regular NameError exception class. It has several causes. You’ll see this error when the code refers to a class or module that it can’t find, often because the code doesn’t include require, which instructs the Ruby file to load the class. In Ruby, variables/methods begin with lowercase letters, while classes begin with uppercase letters. If the code doesn’t reflect this distinction, you’ll receive the Uninitialized Constant exception. Still another possible cause for the NameError error is that you’ve made a simple typo in the code.Ruby is case sensitive, so “TestCode” and “Testcode” are completely different. The code contains mention of rubygems, which is deprecated in all but old versions of Ruby.

Leave a Reply

Your email address will not be published. Required fields are marked *