This project is archived and is in readonly mode.

#6465 ✓duplicate
Alexander Stanko

Problem with autoload and nested modules/classes

Reported by Alexander Stanko | February 24th, 2011 @ 02:00 PM

Hello!

Let I have extras/ in autoload_paths, and also I have classes:

extras/gate/flight.rb

class Gate::Flight
end

extras/gate/reciever.rb

class Gate::Reciever
  Flight #load Gate::Flight for us
  Flight #ArgumentError: Gate is not missing constant Flight! 
end

Is it normal behavior, and I should always type Gate::Flight in all nested modules/classes?
If not, I make a patch to fix this issue.

Comments and changes to this ticket

  • Andrew White

    Andrew White March 5th, 2011 @ 06:39 PM

    • State changed from “new” to “duplicate”
    • Importance changed from “” to “Low”

    This is a duplicate of #5383 - if you rewrite your class definitions so that they're not inline everything will work, e.g:

      module Gate
        class Flight; end
        class Receiver
          Flight #load 
          Flight 
        end
      end
    

    This is because Ruby searches for constants in Object first when defined as ModuleName::ClassName but inside the parent module when nested properly.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages