Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:13:23+00:00 2026-05-27T22:13:23+00:00

What is the correct way to deal with identically named ruby source files and

  • 0

What is the correct way to deal with identically named ruby source files and ensuring the correct file is loaded by a given require statement?

Background

I want to make use of the ruby-geometry gem in my Rails 3 app.

I’m attempting to make use of the ruby-geometry Polygon class:

require 'geometry'  # the main ruby-geometry gem file

module SomeModule
    def SomeMethod(vertices)
        polygon = Geometry::Polygon.new(vertices)
        
        # Do some stuff with polygon...
    end
end

However, whenever I attempt to run this code I get the following error:

NameError: uninitialized constant Geometry::Polygon

This is strange because I seem to be able to work with any of the other ruby-geometry classes without a problem (e.g. Geometry::Point, Geometry::Segment).

The Problem

The problem is that my app contains a source file named polygon.rb (contains an ActiveRecord model) and so does the ruby-geometry gem. So when the ruby-geometry gem requires its own polygon.rb it ends up loading my app’s polygon.rb instead. Presumably this is all down to the order in which ruby searches through directories.

What is the "proper" approach to resolving this naming clash?

Obviously within code you can use modules to differentiate between namespaces to resolve class name clashes. Is there a simple way to differentiate between identically-named source files when require-ing them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:13:23+00:00Added an answer on May 27, 2026 at 10:13 pm

    IMHO this is an error in the geometry gem implementation. It is relying in the $LOAD_PATH environment variable to decide where its requested files are. I rather would prefer to use require_relative or using the File.dirname(__FILE__) value to require relative path files in my gems.

    For solving your issue you can require the geometry gem before Rails is adding its own paths to the $LOAD_PATH environment variable.

    One way to do this that has worked to me is explicitly require this gem in the GEMFILE:

    gem "ruby-geometry", :require => "geometry"
    

    Another way would be to remove your app/models path from the $LOAD_PATH array before require the geometry gem:

    old_load_path = $LOAD_PATH
    $LOAD_PATH.delete(File.expand_path("#{Rails.root}/app/models"))
    require "geometry"
    $LOAD_PATH.replace(old_load_path)
    

    But this is ugly as hell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct way in PHP to deal with decoding strings, such as
I am not sure about the correct way to deal with method expressions in
What is the correct way to import a C++ class from a DLL? We're
What is the correct way to do this? For example, how would I change
What is the correct way to check if a value is a date/number in
Is there a correct way in Windows Forms to flash a titlebar without having
What is the correct way to convert ASP.NET SOAP-based web services to JSON-based responses?
What is the 'correct' way to store a native pointer inside a Java object?
What is the correct way of retrieving maximum values of all columns in a
What is the correct way of iterating over a vector in C++? Consider these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.