Search code examples
rubyrbenv

`require': cannot load such file


I have created a module which then I would inherit in my class to use its methods. But when I run the code. I get error.

mixins2.rb

module ImageUtils 
    def self.status
        puts "Image storing Module"
    end

    def self.preview(image)
    end 

    def self.transfer(image, destination)
    end
end

run.rb

require 'mixins2'

ImageUtils.status

When I run the file $ ruby run.rb. I get following errors:

/Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mixins2 (LoadError)
    from /Users/abhimanyuaryan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from run.rb:1:in `<main>'

Solution

  • You should use require_relative:

    require_relative 'mixins2'
    
    ImageUtils.status