Re: [External] re: Adding a directory to LOAD_PATH
"Tran, Minh" <[email protected]> Thu, 7 Nov 2019 18:03:42 +0000
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <SN6PR05MB53916090620EC39479E4B5DDEE780@SN6PR05MB5391.namprd05.prod.outlook.com> |
--===============0747644058== Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_SN6PR05MB53916090620EC39479E4B5DDEE780SN6PR05MB5391namp_" --_000_SN6PR05MB53916090620EC39479E4B5DDEE780SN6PR05MB5391namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thank you so much Liam for showing me on how to run my test in the live Rub= y environment. Minh ________________________________ From: ruby-talk <[email protected]> on behalf of Leam Hall <l= [email protected]> Sent: Thursday, November 7, 2019 12:53 PM To: Ruby users <[email protected]> Subject: Re: [External] re: Adding a directory to LOAD_PATH Hey, since you're new to Ruby, I'll point you to one of the secrets: irb. It gives you a live Ruby environment to try things out. I'm new to Ruby too, and irb helps me learn. Here's an example: [leam@shaphan ruby]$ pwd; ls lib /home/leam/lang/ruby shot_string.rb [leam@shaphan ruby]$ irb irb(main):001:0> require 'shot_string' Traceback (most recent call last): 6: from /usr/local/bin/irb:23:in `<main>' 5: from /usr/local/bin/irb:23:in `load' 4: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.1.0.pre.3/exe/irb:11:in `<top (required)>' 3: from (irb):1 2: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in `require' 1: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in `require' LoadError (cannot load such file -- shot_string) irb(main):002:0> $LOAD_PATH << File.expand_path("../lib/", __FILE__) =3D> ["/usr/local/lib/ruby/gems/2.7.0/gems/did_you_mean-1.3.1/lib", "/usr/local/lib/ruby/site_ruby/2.7.0", "/usr/local/lib/ruby/site_ruby/2.7.0/x86_64-linux", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/vendor_ruby/2.7.0", "/usr/local/lib/ruby/vendor_ruby/2.7.0/x86_64-linux", "/usr/local/lib/ruby/vendor_ruby", "/usr/local/lib/ruby/2.7.0", "/usr/local/lib/ruby/2.7.0/x86_64-linux", "/home/leam/lang/ruby/lib"] irb(main):003:0> require 'shot_string' =3D> true irb(main):004:0> Leam On 11/7/19 12:41 PM, Tran, Minh 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__) > ------------------------------------------------------------------------ > *From:* ruby-talk <[email protected]> on behalf of Leam > Hall <[email protected]> > *Sent:* Thursday, November 7, 2019 12:16 PM > *To:* Ruby users <[email protected]> > *Subject:* Re: [External] re: Adding a directory to LOAD_PATH > Have you tried something like: > > $LOAD_PATH << File.expand_path("../my_project/", __FILE__) > > That's what I usually do, with "../lib". > > Leam > > > On 11/7/19 11:55 AM, Tran, Minh wrote: >> >> Thank you so much Raj for all of the helps. >> Since I am new to Ruby, could I ask on how could I add my project vendor >> directory to the load path ? >> >> I did a ruby -e 'puts $LOADPATH' command , and it gave me my current >> LOAD_PATH >> >> /usr/local/lib/site_ruby/2.3.0 >> /usr/local/lib/x86_64-linux-gnu/site_ruby >> /usr/local/lib/site_ruby >> /usr/lib/ruby/vendor_ruby/2.3.0 >> /usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.3.0 >> /usr/lib/ruby/vendor_ruby >> /usr/lib/ruby/2.3.0 >> /usr/lib/x86_64-linux-gnu/ruby/2.3.0 >> >> I am still googling for a Ruby command that I could use to add my vendor >> folder to the LOAD_PATH. >> >> Thanks for all of the helps, >> Minh >> >> >> ------------------------------------------------------------------------ >> *From:* ruby-talk <[email protected]> on behalf of Raj >> Sahae <[email protected]> >> *Sent:* Wednesday, November 6, 2019 5:54 PM >> *To:* Ruby users <[email protected]> >> *Subject:* [External] Re: Could not load a Ruby program >> This is sort of a strange thing to do. You are using require while >> dynamically generating the path based on the location of test.rb, which >> could change with respect to your vendor directory. >> Your error message would seem to indicate that the relative path of >> kinetic-sdk.rb from test.rb is not what you are specifying. >> >> If you want to use kinetic-sdk.rb as a library file, then the folder you >> want to load it from should be in your load path. >> There are a couple ways to do this but in my opinion the easiest to test >> with is using "ruby -I" >> >> So if I were you, I would keep kinetic-sdk.rb where it is, and add your >> projects vendor directory to the load path, and then call require in >> test.rb with that relative path. >> >> test.rb would be something like >> >> *#!/usr/bin/ruby >> * >> *puts "Hello World!" >> * >> *require 'kinectic-sdk-rb/kinectic-sdk.rb'* >> * >> * >> And you would run it with a command like >> >> ruby -I my_project/vendor test.rb >> >> You can persist that sort of thing by setting your RUBYLIB env variable, >> or changing load_path inside your test.rb, etc. There are many ways. >> >> >> -Raj >> >> >> On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh <[email protected] >> <mailto:[email protected]>> wrote: >> >> Hello, >> >> I have a scenario that I need to execute a program from the >> other directory than my current directory. >> I got an error when I ran it, and I would like to seek helps >> and expertises. >> >> >> My current directory is at my_project, and the program that >> I would like to execute is >> at my_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb >> >> In my current directory my_project, I have a test.rb which contains >> a very simple line of code such as >> >> #!/usr/bin/ruby >> puts "Hello World!" >> require File.join (File.expand_path (File.dirname(__FILE__)), >> 'vendor/kinectic-sdk-rb/kinectic-sdk.rb') >> >> >> I tried to run the test.rb at my current directory which >> is my_project , and I got the following error message: >> >> Could not load file kinectic-sdk.rb from >> my /my_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb folder. >> >> >> Thanks for all of your helps, >> Minh >> >> > > > Unsubscribe: <mailto:[email protected]?subject=3Dunsubscrib= e> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> > > ------------------------------------------------------------------------ > > 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). Unsubscribe: <mailto:[email protected]?subject=3Dunsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> --_000_SN6PR05MB53916090620EC39479E4B5DDEE780SN6PR05MB5391namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"= > <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 Liam for showing me on how to run my test in th= e live Ruby environment.</div> <div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san= s-serif; font-size: 12pt;"> Minh<br> </div> <div id=3D"appendonsend"></div> <hr style=3D"display:inline-block;width:98%" tabindex=3D"-1"> <div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st= yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> ruby-talk <ruby-ta= [email protected]> on behalf of Leam Hall <[email protected]&= gt;<br> <b>Sent:</b> Thursday, November 7, 2019 12:53 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 class=3D"BodyFragment"><font size=3D"2"><span style=3D"font-size:11pt;= "> <div class=3D"PlainText">Hey, since you're new to Ruby, I'll point you to o= ne of the secrets: <br> irb. It gives you a live Ruby environment to try things out. I'm new to <br= > Ruby too, and irb helps me learn. Here's an example:<br> <br> [leam@shaphan ruby]$ pwd; ls lib<br> /home/leam/lang/ruby<br> shot_string.rb<br> <br> [leam@shaphan ruby]$ irb<br> <br> irb(main):001:0> require 'shot_string'<br> Traceback (most recent call last):<br> 6: from /usr/local/bin/irb= :23:in `<main>'<br> 5: from /usr/local/bin/irb= :23:in `load'<br> 4: from <br> /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.1.0.pre.3/exe/irb:11:in `<top = <br> (required)>'<br> 3: from (irb):1<br> 2: from <br> /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in <br> `require'<br> 1: from <br> /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:81:in <br> `require'<br> LoadError (cannot load such file -- shot_string)<br> <br> irb(main):002:0> $LOAD_PATH << File.expand_path("../lib/"= ;, __FILE__)<br> <br> =3D> ["/usr/local/lib/ruby/gems/2.7.0/gems/did_you_mean-1.3.1/lib&q= uot;, <br> "/usr/local/lib/ruby/site_ruby/2.7.0", <br> "/usr/local/lib/ruby/site_ruby/2.7.0/x86_64-linux", <br> "/usr/local/lib/ruby/site_ruby", <br> "/usr/local/lib/ruby/vendor_ruby/2.7.0", <br> "/usr/local/lib/ruby/vendor_ruby/2.7.0/x86_64-linux", <br> "/usr/local/lib/ruby/vendor_ruby", "/usr/local/lib/ruby/2.7.= 0", <br> "/usr/local/lib/ruby/2.7.0/x86_64-linux", "/home/leam/lang/r= uby/lib"]<br> <br> irb(main):003:0> require 'shot_string'<br> =3D> true<br> irb(main):004:0><br> <br> <br> Leam<br> <br> <br> <br> <br> On 11/7/19 12:41 PM, Tran, Minh wrote:<br> > Thank you so much Leam.<br> > I would like to load the kinetic-sdk.rb program in <br> > /vendor/kinetic-sdk-rb/ to my current working directory /my= _project ;<br> > so would the following command work ?<br> > <br> > $LOAD_PATH << File.expand_path("/vendor/kinectic-sdk-rb&quo= t;, __FILE__)<br> > ----------------------------------------------------------------------= --<br> > *From:* ruby-talk <[email protected]> on behalf of= Leam <br> > Hall <[email protected]><br> > *Sent:* Thursday, November 7, 2019 12:16 PM<br> > *To:* Ruby users <[email protected]><br> > *Subject:* Re: [External] re: Adding a directory to LOAD_PATH<br> > Have you tried something like:<br> > <br> > $LOAD_PATH << File.expand_path(&q= uot;../my_project/", __FILE__)<br> > <br> > That's what I usually do, with "../lib".<br> > <br> > Leam<br> > <br> > <br> > On 11/7/19 11:55 AM, Tran, Minh wrote:<br> >> <br> >> Thank you so much Raj for all of the helps.<br> >> Since I am new to Ruby, could I ask on how could I add my project = vendor <br> >> directory to the load path ?<br> >> <br> >> I did a ruby -e 'puts $LOADPATH' command , and it gave me my curre= nt <br> >> LOAD_PATH<br> >> <br> >> /usr/local/lib/site_ruby/2.3.0<br> >> /usr/local/lib/x86_64-linux-gnu/site_ruby<br> >> /usr/local/lib/site_ruby<br> >> /usr/lib/ruby/vendor_ruby/2.3.0<br> >> /usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.3.0<br> >> /usr/lib/ruby/vendor_ruby<br> >> /usr/lib/ruby/2.3.0<br> >> /usr/lib/x86_64-linux-gnu/ruby/2.3.0<br> >> <br> >> I am still googling for a Ruby command that I could use to ad= d my vendor <br> >> folder to the LOAD_PATH.<br> >> <br> >> Thanks for all of the helps,<br> >> Minh<br> >> <br> >> <br> >> ------------------------------------------------------------------= ------<br> >> *From:* ruby-talk <[email protected]> on behal= f of Raj <br> >> Sahae <[email protected]><br> >> *Sent:* Wednesday, November 6, 2019 5:54 PM<br> >> *To:* Ruby users <[email protected]><br> >> *Subject:* [External] Re: Could not load a Ruby program<br> >> This is sort of a strange thing to do. You are using require while= <br> >> dynamically generating the path based on the location of test.rb, = which <br> >> could change with respect to your vendor directory.<br> >> Your error message would seem to indicate that the relative path o= f <br> >> kinetic-sdk.rb from test.rb is not what you are specifying.<br> >> <br> >> If you want to use kinetic-sdk.rb as a library file, then the fold= er you <br> >> want to load it from should be in your load path.<br> >> There are a couple ways to do this but in my opinion the easiest t= o test <br> >> with is using "ruby -I"<br> >> <br> >> So if I were you, I would keep kinetic-sdk.rb where it is, and add= your <br> >> projects vendor directory to the load path, and then call require = in <br> >> test.rb with that relative path.<br> >> <br> >> test.rb would be something like<br> >> <br> >> *#!/usr/bin/ruby<br> >> *<br> >> *puts "Hello World!"<br> >> *<br> >> *require 'kinectic-sdk-rb/kinectic-sdk.rb'*<br> >> *<br> >> *<br> >> And you would run it with a command like<br> >> <br> >> ruby -I my_project/vendor test.rb<br> >> <br> >> You can persist that sort of thing by setting your RUBYLIB env var= iable, <br> >> or changing load_path inside your test.rb, etc. There are many way= s.<br> >> <br> >> <br> >> -Raj<br> >> <br> >> <br> >> On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh <minh.tran@emoryhealt= hcare.org <br> >> <<a href=3D"mailto:[email protected]">mailto:minh.t= [email protected]</a>>> wrote:<br> >> <br> >> Hello,<br> >> <br> >> I have a scenario= that I need to execute a program from the<br> >> other directory than my current directory.= <br> >> I got an error when I ran it, and I would = like to seek helps<br> >> and expertises.<br> >> <br> >> <br> >> My current directory is at my_project, and= the program that<br> >> I would like to execute is<= br> >> at my_project/vendor/kinectic-sdk-rb/= kinectic-sdk.rb<br> >> <br> >> In my current directory my_project, I have= a test.rb which contains<br> >> a very simple line of code such as<br> >> <br> >> #!/usr/bin/ruby<br> >> puts "Hello World!"<br> >> require File.join (File.expand_path (File.= dirname(__FILE__)),<br> >> 'vendor/kinectic-sdk-rb/kinectic-sdk.rb')<= br> >> <br> >> <br> >> I tried to run the test.rb at my current d= irectory which<br> >> is my_project , and I got the followi= ng error message:<br> >> <br> >> Could not load file kinectic-sdk.rb&n= bsp; from<br> >> my /my_project/vendor/kinectic-= sdk-rb/kinectic-sdk.rb folder.<br> >> <br> >> <br> >> Thanks for all of your helps,<br> >> Minh<br> >> <br> >> <br> > <br> > <br> > Unsubscribe: <<a href=3D"mailto:[email protected]?sub= ject=3Dunsubscribe">mailto:[email protected]?subject=3Dunsubs= cribe</a>><br> > <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby= -talk">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>>= <br> > <br> > ----------------------------------------------------------------------= --<br> > <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, distributio= n<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> <br> <br> Unsubscribe: <<a href=3D"mailto:[email protected]?subject= =3Dunsubscribe">mailto:[email protected]?subject=3Dunsubscrib= e</a>><br> <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk= ">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>><br> </div> </span></font></div> </body> </html> --_000_SN6PR05MB53916090620EC39479E4B5DDEE780SN6PR05MB5391namp_-- --===============0747644058== 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> --===============0747644058==--