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 giving great 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 <ruby-= [email protected]> on behalf of Martin DeMello <martindemell= [email protected]><br> <b>Sent:</b> Thursday, November 7, 2019 2:33 PM<br> <b>To:</b> Ruby users <[email protected]><br> <b>Subject:</b> Re: [External] re: Adding a directory to LOAD_PATH</font> <div> </div> </div> <div> <div dir=3D"ltr"> <div dir=3D"ltr">On Thu, Nov 7, 2019 at 9:42 AM Tran, Minh <<a href=3D"m= ailto:[email protected]">[email protected]</a>> = 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 load the kinetic-sdk.rb program in /vendor/kinetic-sdk= -rb/ 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 << File.expand_path("/vendor/kinecti= c-sdk-rb", __FILE__)</font> </div> </div> </blockquote> <div><br> </div> <div>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&= quot;.</div> <div><br> </div> <div>Also, if you want to load the file as require "kinetic-sdk-rb/kin= etic-sdk.rb" 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 > /tmp/ruby/foo/bar.rb<br> def f <br> puts "hello world"<br> end<br> <br> </font></div> <div><font face=3D"monospace">$ irb<br> irb(main):001:0> $LOAD_PATH << "/tmp/ruby"<br> =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", &q= uot;/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", "/usr/lib/ruby/2.5.0", &q= uot;/usr/lib/x86_64-linux-gnu/ruby/2.5.0", "/tmp/ruby"]<br> irb(main):002:0> require 'foo/bar'<br> =3D> true<br> irb(main):003:0> f<br> hello world</font><br> </div> <div><br> </div> <div>martin </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==--