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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:26:16+00:00 2026-05-28T05:26:16+00:00

I was building my own class that resides in /lib folder and debugging with

  • 0

I was building my own class that resides in /lib folder and debugging with rails console. I quickly comes to a problem, which I have to reload! my console everytime I modified my class file. Would like to know how to auto-reload this when file changed.

Following is my configuration:

Class Location

/lib/book.rb

Code

class Book  
  def hello
    puts 'hello'
  end
end

config/application.rb

config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]

Console

rails c
Book.new.hello
  • 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-28T05:26:17+00:00Added an answer on May 28, 2026 at 5:26 am

    It doesn’t look to me like guard will do this, but I could be wrong. My solution, since this is coming up a lot today is to add a load_lib function to my .irbrc file:

    (note that this is Rails specific, perhaps someone has a suggestion about that)

     def load_lib
        path = File.join( Rails.root, 'lib') 
        failures = []
        Dir.glob("#{path}/**/*.rb").each {  |file|
        puts "loading: #{file} ... "
        begin
          load file
        rescue => ex
          failures << file 
        end
       } 
      # this second pass is here to try to catch anything that 
      # is dependent on something else
      # could be improved, but is working fine for my needs
      double_failures = []
      for file in failures 
        begin
          load file
        rescue => ex1
          double_failures << file 
        end
      end 
    
      if double_failures.size > 0 
        puts "these files failed twice"
        for file in double_failures
          puts file
        end
      end 
    end
    

    The in the Rails console I just need to run load_lib and my library code is loaded in. It’s brute force and might not be perfect but it is meeting my needs. It also doesn’t answer your question, but it’s close enough?

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

Sidebar

Related Questions

Currently I'm building my own script VM manager class in C++. I have no
I am building my own CRM access database that will contain a list of
I am building my own local search UI element that gives local search suggestions
I am building a small device with its own CPU (AVR Mega8) that is
I'm building a public website which has its own domain name with pop/smtp mail
I'm building a Rails site that, among other things, allows users to build their
I recently tried building my own shared and weak pointers. Code that compiles using
I'm building an Eclipse plugin that talks to a REST interface which uses Basic
I have to store scheduled events, (like say class times, for example) that can
I'm building my own String class and I want to write my own replace

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.