Reputation: 12673
I have a project with class Matrix < ActiveRecord::Base
, and I'm hitting situations where Matrix.where
is crashing because it's trying to access the Matrix < Enumerable
class from ruby.
Is there a way to specify which Matrix
I want, like ActiveRecord::Base::Matrix
?
I know I could rename the model, but it would be a pain (old spaghetti project)
Upvotes: 1
Views: 36
Reputation: 211570
Rename it or be forever battling Ruby core. You can't get around this. Rails chose to put model names in the root namespace as it's very convenient, but leads to problems when that conflicts with either Rails or Ruby.
Solutions:
Matrix
has a chance to usurp it
require 'matrix'
show up somewhereMatrix
to be the Ruby thing and not your random modelMyProject::Matrix
MMatrix
as a reminder that this name was a bad idea from the outsetThe good news is that if this is a fairly unique string, then a global replace of Matrix
to the alternate name is probably not going to be that bad.
Upvotes: 1