Where to store abbreviations for long class names in Rails?

Viewed 269

I constantly need to use long class name like

SomeReallyLongModuleName::AnotherLongModuleName::YetAnotherLongClassName

in the project. I want to access this class by something like YALCN. Where it's the best to keep definition like

YALCN = SomeReallyLongModuleName::AnotherLongModuleName::YetAnotherLongClassName

And is it a common practice, or people constantly use fully-qualified long name?

3 Answers

If this is only for Rails console usage, I'd put them into /lib/aliases.rb or somewhere similar and require the file when needed.

You could make "local" aliases. Something like this:

class Another
  YALCN = SomeReallyLongModuleName::AnotherLongModuleName::YetAnotherLongClassName

  def do_something
    YALCN.new # or whatever
  end
end

To avoid problems with autoloading, I'd keep the short constants in the same place they're used.

And is it a common practice, or people constantly use fully-qualified long name?

I haven't seen this too often.

Related