Wrong autoload


I have Parser::Typography::CharTypographer, in parser/typography/char_typographer.rb:

require File.expand_path("../base", __FILE__)

module Parser

module Typography

class CharTypographer < Base


Sometimes (not always) it inherits from Parser::Base as seen in debugger:

[34, 43] in /private/var/site/js-dev/lib/parser/node/tag.rb

=> 39:         typographer = Typography::CharTypographer.new

(byebug) Typography::CharTypographer.superclass


How can this happen?!?

I explicitly include ‘base.rb’ from current directory in the first line!

P.S. Here’s the files layout : http://ilyakantor.ru/screen/2014-06-11_2229.png

Inheritance should happen from the first base, not the second one.

Hi Ilya,

This is not the appropriate mailing list for that, this one is only to discuss rails core features and bugs, but try to inherit from ::Base, instead of Base.


The behavior feels like a bug that’s why I posted it here.

Kind of strange when I explicitly require base class and the inheritance still goes wrong.

I suspect it could be a combination of factors. This is something that
could explain what you see:

1. Parser::Typography::Base is autoloaded

2. Parser::Typography::CharTypographer is autoloaded

3. Files change and a new request comes

4. Parser::Base is autoloaded

5. Parser::Typography::CharTypographer is autoloaded

If that happened, it would explain why you see this mismatch only
sometimes, it would depend on whether 4 happened or not before getting to 5
and that would depend on the order of execution of a particular request.

Problem is "require". When 5 runs, require says it already loaded that file
so it passes. But if 1 happened Parser::Typography::Base would have been
removed after 3. If 4 happened Ruby is able to resolve "Base" to Parser::Base
and AS never gets a chance. If 4 didn't happen then AS autoloads
because it goes first in the search. See where does the randomness may come

That's a possible explanation and it wouldn't be a bug, please change the
require line with

    require_dependency 'parser/typography/base'