Home > Back-end >  How to fix Ruby error: `require': cannot load such file -Programing Ruby 1.9 & 2.0 4th edition
How to fix Ruby error: `require': cannot load such file -Programing Ruby 1.9 & 2.0 4th edition

Time:09-21

This is my first post and I apologize for any errors in my formatting.

I'm using AWS cloud9 as my IDE. I am trying to load a file, however I keep getting this error:

Traceback (most recent call last):
    2: from gserver:9:in `<main>'
    1: from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- gserver (LoadError)

My gserver-logger.rb code is:

require 'gserver'

class LogServer < GServer

def initialize
  super(12345)
end

def serve(client)
  client.puts get_end_of_log_file
end


private

 def get_end_of_log_file
   File.open("/var/log/system.log") do |log|
     log.seek(-500, IO::SEEK_END)   
     log.gets                        
     log.read                        
     end
   end
 end

server = LogServer.new
server.start.join

I have verified that gserver is in the same directory and therefore my code should be able to access the file gserver-logger.rb. All of this is from the book, Programming Ruby 1.9 & 2.0 4th edition.pdf page 86. Thank you for your assistance.

CodePudding user response:

gserver used to be part of Ruby's standards library for some time. However, it was removed from the standards library with Ruby 2.2.0 since it was basically unmaintained and had no tests.

This (un-)maintenance status has not really changed since. If you still need the functionality of the library, you can install and use the gserver gem which contains the code state as it was removed form the standards library. However, I would strongly recommend to use something else instead...

  • Related