Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby/rspec not recognizing Ruby class with the same name as a former module

I have a ruby class, Feedbin, that was previously the name of a module. When I try and call any methods in the class, a TypeError is thrown: `': Feedbin is not a class (TypeError)

When I change the name of the class, but appending an s for example, things seem to work as expected.

The same program used to have a module named Feedbin as well, but the module no longer exists.

Old:

module Feedbin
  class Api
  end
end

New:

class Feedbin
end

How can I get rid of the "Feedbin is not a class" type error? What is causing this?

like image 866
Colby Aley Avatar asked Jul 16 '13 06:07

Colby Aley


1 Answers

A non-class module cannot be changed into a class. Once you define a (non-class) module, it cannot be changed into a class. You perhaps have:

class Feedbin
...

somewhere prior to where you have

module Feedbin
...

Change that class into module, or use a different name instead of Feedbin for one of those.

Or, does the error message occur for certain methods? Certain methods can be defined on classes only. For example, if you call Feedbin.new, or something that calls initialize on Feedbin, and change Feedbin into a non-class module, then that would cause an error. In such case, use a different name for the non-class module.

like image 125
sawa Avatar answered Nov 09 '22 06:11

sawa