-3

I'm packaging my own gem, which includes a module called Convert3D, and a class called ShapeSet.

The following error occurs when I try to call a method of the Convert3D module from within the initialize method of ShapeSet. The Convert3D module has been required and the method works from the irb context from which ShapeSet.new is being called.

NameError: uninitialized constant ShapeSet::Convert3d

Given that there is no reference to "ShapeSet::Convert3d" anywhere ever, what is ruby doing here, and what might I be doing wrong to cause it?

I'm using Matz Ruby 1.9.3 on OSX 10.8.2

Nat
  • 2,689
  • 2
  • 29
  • 35
  • Have you given any thought to including an elided module/class definition in your question so that folks don't have to guess what your code looks like? – Todd A. Jacobs Feb 17 '13 at 17:44
  • Yep, but decided against it since I figured the relevant specifics are more clearly communicated by describing the key points than by replicating a simplified version of my code. – Nat Feb 17 '13 at 17:49

2 Answers2

2

You have a typo: you forgot to capitalize the d.

By writing Convert3d in a method of the Shapeset class, you are asking ruby if Shapeset::Convert3d OR ::Convert3d exists and it is finding neither.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
2

Because you are referring to Convert3D inside of the context of ShapeSet, ruby tries to look for a ShapeSet::Convert3D. Not sure why this sometimes happens, and sometimes not.

But the solution is simple: to be sure you are referring to Convert3D in the global namespace, you can always write ::Convert3D.

HTH.

nathanvda
  • 49,707
  • 13
  • 117
  • 139