Trenton Tyler
Trenton Tyler

Reputation: 1712

uninitialized constant Syke::Core RubyGem

I am building a RubyGem to generate test data and am running into an issue while building it. I have the main syke.rb file that was genereated from the initial gem build.

require "syke/version"
require "syke/internet"

mydir = __dir__

require 'i18n'

I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
I18n.available_locales = [:en]

module Syke
  class Core
    class << self
      def get(key)
        I18n.t("syke.#{key}")
      end
    end
  end
end

I am trying to pull values from a .yml file so in my internet.rb file I have this:

module Syke
  class Internet < Core
    class << self
      def email
        get('internet.domain')
      end
    end
  end
end 

I am currently getting this error while trying to test the application with rspec:

NameError: uninitialized constant Syke::Core

I have the internet class inheriting the Core class under the Syke module so I am confused why I would be getting this error message. Anybody have any idea? Thanks.

Upvotes: 0

Views: 26

Answers (1)

Chris Hall
Chris Hall

Reputation: 905

The problem is that your require "syke/internet" is before you've defined Syke::Core.

Personally, I would move the definition of Syke::Core into it's own file that you can require inside either the main syke.rb (before requiring internet) file or in the internet.rb file itself.

Upvotes: 1

Related Questions