how does rails implicitly import functions from gems?

Viewed 3818

I am new to ruby and rails. I see that any gems that I have included, I can directly use its functions in my code. I do not see any imports for the code, nor any name spaces for the functions. Isn't this recipe for conflicts, if the gems contain functions with same names ?

So -

How does ruby/rails imports the functions, how does it map a function to a gem ? Can it lead to conflicts when 2 gems contain the same funcitons ? If I want to explicitly use a ruby library, how will I import its code ? Is there namespacing in ruby?

3 Answers

If you look in config/application.rb, you'll see how it does it:

Bundler.require(*Rails.groups)

That's it! Bundler handles requiring all of the gems automatically so you don't have to in every file you use. For more details, see the docs.

Related