1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

NameError: uninitialized constant Object::Something

By

Caucasian businessman working in office
Jetta Productions/Blend Images/Getty Images

Problem: You encounter an error reading NameError: uninitialized constant Something or NameError: uninitialized constant Object::Something (with various class names in place of Something).

Solution: You've most likely referred to a class or module that doesn't exist. Most likely, you've forgotten to require a gem or library needed for the code to work, or you've made a typo. Another possibility is that the class you'd like to refer to is in another module. If that's the case, you'll have to refer to it with its full name as in the following code.


#!/usr/bin/env ruby

module MyModule
 class MyClass; end
end

c = MyModule::MyClass.new
  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. FAQs
  6. NameError: uninitialized constant Object::Something

©2014 About.com. All rights reserved.