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 7165811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:18:43+00:00 2026-05-28T14:18:43+00:00

I create a custom class which I call MyClass in a module MyModule module

  • 0

I create a custom class which I call MyClass in a module MyModule

module MyModule
 class MyClass
   def initialize
     ... # Some code here
   end
 end
end

I save this code in a file called mymodule.rb

I place this file in the lib directory of my rails application, and add the following line to my application.rb

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

When I fire up the rails console and try to use this file. it just doesnt work.

m = MyModule::MyClass.new()
NameError: uninitialized constant MyModule
from (irb):1
from /Users/matt/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.6/lib/rails/commands/console.rb:44:in `start'
from /Users/matt/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.6/lib/rails/commands/console.rb:8:in `start'
from /Users/matt/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.6/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

What do I need to do in order to be able to use that class in the rails console

Any help appreciated

  • 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-05-28T14:18:44+00:00Added an answer on May 28, 2026 at 2:18 pm

    Name the file my_class.rb and place it in the directory my_module. That should fix your problem.

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

Sidebar

Related Questions

I've created a custom module (which currently only defines a new Exception class), and
I've created a custom VS template which uses an IWizard class to do some
I like to create an instance of a custom class by passing it a
How can I use reflection to create a generic List with a custom class
I have a custom thread pool class, that creates some threads that each wait
I am not using a dialog, I'm using my own custom class which I
I am trying to create a custom HTML Helper that encapsulates some presentation logic
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I have a java class which fires custom java events. The structure of the
In a web MVC model, which class/object has the responsibility/function to call 404 page?

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.