I have the following structure of files:
In the execute.rb I have the code bellow:
#!/usr/bin/ruby
require 'lib/my_class'
my_object= MyClass.new
my_object.some_method
And this is the code of my_class.rb:
class MyClass
def some_method
puts 'OK'
end
end
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.
I fix this following the hint of @Dogbert.
At execute.rb code it's necessary replace:
require 'lib/my_class'
for:
require_relative 'lib/my_class'
I had the same issue. You could also use load 'lib/my_class.rb' require_relative assumes the .rb suffix and so, you don't have to write it out. load requires the whole full filename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With