monteirobrena monteirobrena - 1 year ago 129
Ruby Question

How fix this error: kernel_require.rb:45:in `require': cannot load such file?

I have the following structure of files:

  • execute.rb

  • lib

    • my_class.rb

In the execute.rb I have the code bellow:


require 'lib/my_class'



And this is the code of my_class.rb:

class MyClass
def some_method
puts 'OK'

So, I tried run the execute.rb:

ruby execute.rb

But I receive this error:

/home/vagrant/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- lib/my_class (LoadError)
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from execute.rb:3:in `<main>'

Can anyone help me? I'll appreciate any help.
Thanks a lot.

Answer Source

I fix this following the hint of @Dogbert.

At execute.rb code it's necessary replace:

require 'lib/my_class'


require_relative 'lib/my_class'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download