Re: [External] re: Adding a directory to LOAD_PATH

"Tran, Minh" <[email protected]> Thu, 7 Nov 2019 19:48:22 +0000
Newsgroups gmane.comp.lang.ruby.general
Message-ID <SN6PR05MB53916B9586C58AACE9710A28EE780@SN6PR05MB5391.namprd05.prod.outlook.com>
--===============1497520031==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_SN6PR05MB53916B9586C58AACE9710A28EE780SN6PR05MB5391namp_"

--_000_SN6PR05MB53916B9586C58AACE9710A28EE780SN6PR05MB5391namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thank you so much martin for giving great explanation and example.
Regards,
Minh

________________________________
From: ruby-talk <[email protected]> on behalf of Martin DeMel=
lo <[email protected]>
Sent: Thursday, November 7, 2019 2:33 PM
To: Ruby users <[email protected]>
Subject: Re: [External] re: Adding a directory to LOAD_PATH

On Thu, Nov 7, 2019 at 9:42 AM Tran, Minh <[email protected]<ma=
ilto:[email protected]>> wrote:
Thank you so much Leam.
I would like to load the kinetic-sdk.rb program in /vendor/kinetic-sdk-rb/ =
 to my current working directory /my_project ;
so would the following command work ?

$LOAD_PATH << File.expand_path("/vendor/kinectic-sdk-rb", __FILE__)

File.expand_path converts things like ".." and "~" to absolute paths; since=
 you already have an absolute path you don't need it here. You can just say=
 $LOAD_PATH << "/vendor/kinetic-sdk-rb".

Also, if you want to load the file as require "kinetic-sdk-rb/kinetic-sdk.r=
b" then you want only /vendor in your $LOAD_PATH, not /vendor/kinetic-sdk-r=
b - the require path is relative to the LOAD_PATH entry. Here's an example:


$ mkdir -p /tmp/ruby/foo

$ cat > /tmp/ruby/foo/bar.rb
def f
  puts "hello world"
end

$ irb
irb(main):001:0> $LOAD_PATH << "/tmp/ruby"
=3D> ["/usr/share/rubygems-integration/all/gems/did_you_mean-1.2.1/lib", "/=
usr/local/lib/site_ruby/2.5.0", "/usr/local/lib/x86_64-linux-gnu/site_ruby"=
, "/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/2.5.0", "/usr/lib/=
x86_64-linux-gnu/ruby/vendor_ruby/2.5.0", "/usr/lib/ruby/vendor_ruby", "/us=
r/lib/ruby/2.5.0", "/usr/lib/x86_64-linux-gnu/ruby/2.5.0", "/tmp/ruby"]
irb(main):002:0> require 'foo/bar'
=3D> true
irb(main):003:0> f
hello world

martin

________________________________

This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).

--_000_SN6PR05MB53916B9586C58AACE9710A28EE780SN6PR05MB5391namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Thank you so much martin for&nbsp;giving great&nbsp;explanation and example=
.</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Regards,</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Minh<br>
</div>
<div>
<div id=3D"appendonsend"></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<br>
</div>
<hr tabindex=3D"-1" style=3D"width: 98%; display: inline-block;">
<div id=3D"divRplyFwdMsg" dir=3D"ltr"><font color=3D"#000000" face=3D"Calib=
ri, sans-serif" style=3D"font-size: 11pt;"><b>From:</b> ruby-talk &lt;ruby-=
[email protected]&gt; on behalf of Martin DeMello &lt;martindemell=
[email protected]&gt;<br>
<b>Sent:</b> Thursday, November 7, 2019 2:33 PM<br>
<b>To:</b> Ruby users &lt;[email protected]&gt;<br>
<b>Subject:</b> Re: [External] re: Adding a directory to LOAD_PATH</font>
<div>&nbsp;</div>
</div>
<div>
<div dir=3D"ltr">
<div dir=3D"ltr">On Thu, Nov 7, 2019 at 9:42 AM Tran, Minh &lt;<a href=3D"m=
ailto:[email protected]">[email protected]</a>&gt; =
wrote:<br>
</div>
<div class=3D"x_gmail_quote">
<blockquote class=3D"x_gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; pad=
ding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1=
px; border-left-style: solid;">
<div dir=3D"ltr">
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Thank you so much Leam. </div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
I would like to&nbsp;load the kinetic-sdk.rb program in /vendor/kinetic-sdk=
-rb/&nbsp;&nbsp;to my current working directory /my_project ;
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
so would the following command work ?</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<br>
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<font size=3D"3">$LOAD_PATH &lt;&lt; File.expand_path(&quot;/vendor/kinecti=
c-sdk-rb&quot;, __FILE__)</font>&nbsp; &nbsp;</div>
</div>
</blockquote>
<div><br>
</div>
<div>File.expand_path converts things like &quot;..&quot; and &quot;~&quot;=
 to absolute paths; since you already have an absolute path you don't need =
it here. You can just say $LOAD_PATH &lt;&lt; &quot;/vendor/kinetic-sdk-rb&=
quot;.</div>
<div><br>
</div>
<div>Also, if you want to load the file as require &quot;kinetic-sdk-rb/kin=
etic-sdk.rb&quot; then you want only /vendor in your $LOAD_PATH, not /vendo=
r/kinetic-sdk-rb - the require path is relative to the LOAD_PATH entry. Her=
e's an example:</div>
<div><br>
</div>
<div><font face=3D"monospace"><br>
</font></div>
<div><font face=3D"monospace">$ mkdir -p /tmp/ruby/foo<br>
<br>
</font></div>
<div><font face=3D"monospace">$ cat &gt; /tmp/ruby/foo/bar.rb<br>
def f &nbsp; <br>
&nbsp; puts &quot;hello world&quot;<br>
end<br>
<br>
</font></div>
<div><font face=3D"monospace">$ irb<br>
irb(main):001:0&gt; $LOAD_PATH &lt;&lt; &quot;/tmp/ruby&quot;<br>
=3D&gt; [&quot;/usr/share/rubygems-integration/all/gems/did_you_mean-1.2.1/=
lib&quot;, &quot;/usr/local/lib/site_ruby/2.5.0&quot;, &quot;/usr/local/lib=
/x86_64-linux-gnu/site_ruby&quot;, &quot;/usr/local/lib/site_ruby&quot;, &q=
uot;/usr/lib/ruby/vendor_ruby/2.5.0&quot;, &quot;/usr/lib/x86_64-linux-gnu/=
ruby/vendor_ruby/2.5.0&quot;,
 &quot;/usr/lib/ruby/vendor_ruby&quot;, &quot;/usr/lib/ruby/2.5.0&quot;, &q=
uot;/usr/lib/x86_64-linux-gnu/ruby/2.5.0&quot;, &quot;/tmp/ruby&quot;]<br>
irb(main):002:0&gt; require 'foo/bar'<br>
=3D&gt; true<br>
irb(main):003:0&gt; f<br>
hello world</font><br>
</div>
<div><br>
</div>
<div>martin&nbsp;</div>
</div>
</div>
</div>
</div>
<br>
<hr>
<font face=3D"Arial" color=3D"Gray" size=3D"1"><br>
This e-mail message (including any attachments) is for the sole use of<br>
the intended recipient(s) and may contain confidential and privileged<br>
information. If the reader of this message is not the intended<br>
recipient, you are hereby notified that any dissemination, distribution<br>
or copying of this message (including any attachments) is strictly<br>
prohibited.<br>
<br>
If you have received this message in error, please contact<br>
the sender by reply e-mail message and destroy all copies of the<br>
original message (including attachments).<br>
</font>
</body>
</html>

--_000_SN6PR05MB53916B9586C58AACE9710A28EE780SN6PR05MB5391namp_--

--===============1497520031==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--===============1497520031==--