On Sun, Sep 23, 2012 at 7:46 PM, S Ahmed wrote:

I see what your saying.

I guess what I am asking then is, when developing your own gem, say I am
developing my gem on my Mac in:

/Users/me/projects/ruby/gem/some_gem_name/

So this means I have to somehow modify my load_path so that I can just
require things like:

require 'folder/file'


And then when I publish my gem and users use my gem, things will just work
since the gem is installed by default at a path that ruby will look in?

How then do gem developers modify their path to have this work?
They don't. They usually end up using something that 7Stud also mentioned.
Which is to say require_relative or they add a relative path to the $PATH
variable in some way.

So they don't modify their path, they use the environment that will be
given, and take advantage of this.

You can also use the file itself... you will see many different examples of
this in different gems. For example, in Rails Admin, spec/spec_helper.rb
you will see require File.expand_path('../dummy_app/config/environment',
__FILE__)

This takes the relative location of that file and load it that way, and so
will not require it to know exactly where it was installed, but it can rely
on its own project structure.

In IRB go ahead and do that... >> File.expand_path('.') you will see what I
mean. From that piece of information, build your path as you need to
require things for your project.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 11 of 11 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 23, '12 at 9:30p
activeSep 24, '12 at 2:16a
posts11
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase