Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:39:56+00:00 2026-06-04T08:39:56+00:00

I am encountering a strange bug in my code. I have a rails application

  • 0

I am encountering a strange bug in my code. I have a rails application with the following two files in the lib:

lib/module_one/module_two/class_one.rb

module ModuleOne
  module Moduletwo
    class ClassOne
      class << self
        def test
          puts 'Class one'
          ClassTwo.test
        end
      end
    end
  end
end

and

lib/module_one/module_two/class_two.rb

module ModuleOne
  module ModuleTwo
    class ClassTwo
      def self.test
        puts 'Class two'
      end
    end
  end
end

Now my problem is, that when I go into the console and write:

ModuleOne::ModuleTwo::ClassOne.test

it throws the following: NameError: uninitialized constant ClassTwo

The strange thing is, that the problem seems to be connected to the use of class << self instead of self.method. If I change the class_one.rb file like this it works!:

module ModuleOne
  module ModuleTwo
    class ClassOne
      def self.test
        puts 'Class one'
        ClassTwo.test
      end
    end
  end
end

Im loading the files in application.rb like this:

config.autoload_paths += %W(#{config.root}/lib)

Is this a bug in rails, or is it just me getting something all wrong?

Im using rails 3.1.3 btw

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:39:57+00:00Added an answer on June 4, 2026 at 8:39 am

    (Only a partial answer, but need formatting.)

    It’s because of how class << self works.

    For example, if you change it to:

    class << self
      def test
        self::ClassTwo.test
      end
    end
    

    it works fine.


    Edit; too long for reasonable comment.

    I’m poking around a bit… On an intuitive level it makes sense to me, I’m just not sure why yet. Don’t know if I knew a real reason once, or if I’m just making it up.

    I’m not sure why self seems to refer to the module, though; the “Programming Ruby 1.9” book doesn’t go in to enough depth on the class << semantics. I’ll tweet something and refer to this question and someone smarter will create a real answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple nD-vector class, but am encountering a strange bug. I've stripped
I am encountering a strange problem when trying to create two dropdowns where the
I have the following code: (please pardon the length of this code). I am
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
I'm encountering the following problem - I have simple GWT overlay types, and I'm
I'm encountering a strange bug in Safari where, when I serve MP4 video through
I'm encountering a strange OpenGL Bug. OpenGL is pretty new to me, but we're
I'm amused by a strange error that I'm encountering in my program. I have
I'm encountering a very strange problem: my delete actions in rails don't work anymore.
I am dynamically creating CSV files using C#, and I am encountering some strange

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.