Could not load a Ruby program
"Tran, Minh" <[email protected]> Wed, 6 Nov 2019 21:38:42 +0000
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <SN6PR05MB5391BA17FB6367196318534DEE790@SN6PR05MB5391.namprd05.prod.outlook.com> |
--===============1647319645==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_SN6PR05MB5391BA17FB6367196318534DEE790SN6PR05MB5391namp_"
--_000_SN6PR05MB5391BA17FB6367196318534DEE790SN6PR05MB5391namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello,
I have a scenario that I need to execute a program from the other direc=
tory 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/kinec=
tic-sdk-rb/kinectic-sdk.rb')
I tried to run the test.rb at my current directory which is my_project , an=
d I got the following error message:
Could not load file kinectic-sdk.rb from my /my_project/vendor/kinectic-s=
dk-rb/kinectic-sdk.rb folder.
Thanks for all of your helps,
Minh
________________________________
From: ruby-talk <[email protected]> on behalf of Dan Fitzpatr=
ick <[email protected]>
Sent: Friday, October 25, 2019 12:30 AM
To: [email protected] <[email protected]>
Subject: [External] Re: How to compare a hash key with a string value
Hello Dun,
First I would change the name of your variable "hash" to something else
because it is not a hash, it is an array of hashes. Since it represents
a list of people, I would call it people.
The main issue is that your keys are getting converted to symbols. So
none of the objects have the "width" attribute as a string.
This is the only thing that continuously annoys me about Ruby:
a =3D
{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","p=
age":1,"page_name":"Step
1","width":"100%"}
=3D> {:label=3D>"Name", :value=3D>"Bob", :identifier=3D>"field2",
:type=3D>"oneLineText", :page=3D>1, :page_name=3D>"Step 1", :width=3D>"100%=
"}
b
=3D{"label"=3D>"Name","value"=3D>"Bob","identifier"=3D>"field2","type"=3D>"=
oneLineText","page"=3D>1,"page_name"=3D>"Step
1","width"=3D>"100%"}
=3D> {"label"=3D>"Name", "value"=3D>"Bob", "identifier"=3D>"field2",
"type"=3D>"oneLineText", "page"=3D>1, "page_name"=3D>"Step 1", "width"=3D>"=
100%"}
a['width']
=3D> nil
b['width']
=3D> "100%"
a[:width]
=3D> "100%"
Here is your code working:
people =3D
[{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","=
page":1,"page_name":"Step
1","width":"100%"},{"label":"Email","value":"[email protected]","identifier"=
:"field3","type":"email","page":1,"page_name":"Step
1","width":"100%"},{"label":"Phone
Number","value":"","identifier":"field7","type":"oneLineText","page":1,"pag=
e_name":"Step
1","width":"100%"},{"label":"Comments","value":"some information about
the
compagny","identifier":"field5","type":"textarea","page":1,"page_name":"Ste=
p
1","width":"100%"}]
# If you only need the width attribute, you can do this (no loop on the
attributes needed):
people.each_with_index do |person, i|
puts "Person is #{i+1}" # First person displays as 1 instead of 0
puts "The value of width is #{person[:width]}" if person.has_key?(:width=
)
end
# If needed, loop through all the attributes of person (like in your
example), but change to detecting symbol keys
people.each_with_index do |person, i|
puts "Person is #{i+1}" # First person is 1 instead of 0
person.each do |key, value|
if key =3D=3D :width
puts "The value of width is #{value}"
end
end
end
Also, if you are defining your hashes, you don't need to use JSON format
with quoted keys, you can just do:
a =3D {label: "Name", value: "Bob", identifier: "field2", type:
"oneLineText", page: 1, page_name: "Step 1", width: "100%"}
Dan
On 10/24/2019 1:35 AM, Tran, Minh wrote:
Unsubscribe: <mailto:[email protected]?subject=3Dunsubscribe>
<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).
--_000_SN6PR05MB5391BA17FB6367196318534DEE790SN6PR05MB5391namp_
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;">
Hello, </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;">
I have a scenario that I need to execute a program =
from the other directory than my current directory.</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
I got an error when I ran it, and I would like to seek helps and exper=
tises.</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;">
<br>
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
My current directory is at my_project, and the program that I&nbs=
p;would like to execute is at my_project/vendor/kinectic-sdk=
-rb/kinectic-sdk.rb
</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;">
In my current directory my_project, I have a test.rb which contains a=
very simple line of code such as
</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;">
<span>#!/usr/bin/ruby<br>
</span></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
puts "Hello World!"<br>
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<span>require File.join (File.expand_path (File.dirname(__FILE__)), 'vendor=
/kinectic-sdk-rb/kinectic-sdk.rb')</span></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<span>I tried to run the test.rb at my current directory which is =
;my_project , and I got the following error message:</span></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<span>Could not load file kinectic-sdk.rb from my /my=
_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb folder. </span></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;">
<br>
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Thanks for all of your helps,</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Minh</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;">
<br>
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<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 Dan Fitzpatrick <dan@eparkla=
bs.com><br>
<b>Sent:</b> Friday, October 25, 2019 12:30 AM<br>
<b>To:</b> [email protected] <[email protected]><br>
<b>Subject:</b> [External] Re: How to compare a hash key with a string valu=
e</font>
<div> </div>
</div>
<div class=3D"BodyFragment"><font size=3D"2"><span style=3D"font-size: 11pt=
;">
<div class=3D"PlainText">Hello Dun,<br>
<br>
<br>
First I would change the name of your variable "hash" to somethin=
g else <br>
because it is not a hash, it is an array of hashes. Since it represents <br=
>
a list of people, I would call it people.<br>
<br>
<br>
The main issue is that your keys are getting converted to symbols. So <br>
none of the objects have the "width" attribute as a string.<br>
<br>
<br>
This is the only thing that continuously annoys me about Ruby:<br>
<br>
<br>
a =3D <br>
{"label":"Name","value":"Bob","=
;identifier":"field2","type":"oneLineText&quo=
t;,"page":1,"page_name":"Step
<br>
1","width":"100%"}<br>
<br>
=3D> {:label=3D>"Name", :value=3D>"Bob", :iden=
tifier=3D>"field2", <br>
:type=3D>"oneLineText", :page=3D>1, :page_name=3D>"=
Step 1", :width=3D>"100%"}<br>
<br>
<br>
b <br>
=3D{"label"=3D>"Name","value"=3D>"=
Bob","identifier"=3D>"field2","type"=
=3D>"oneLineText","page"=3D>1,"page_name&quo=
t;=3D>"Step
<br>
1","width"=3D>"100%"}<br>
=3D> {"label"=3D>"Name", "value"=3D>=
"Bob", "identifier"=3D>"field2", <br>
"type"=3D>"oneLineText", "page"=3D>1, &=
quot;page_name"=3D>"Step 1", "width"=3D>&quo=
t;100%"}<br>
<br>
a['width']<br>
<br>
=3D> nil<br>
<br>
b['width']<br>
<br>
=3D> "100%"<br>
<br>
a[:width]<br>
<br>
=3D> "100%"<br>
<br>
<br>
Here is your code working:<br>
<br>
people =3D <br>
[{"label":"Name","value":"Bob",&quo=
t;identifier":"field2","type":"oneLineText&qu=
ot;,"page":1,"page_name":"Step
<br>
1","width":"100%"},{"label":"Email&=
quot;,"value":"[email protected]","identifier"=
:"field3","type":"email","page":1,&=
quot;page_name":"Step
<br>
1","width":"100%"},{"label":"Phone =
<br>
Number","value":"","identifier":"fi=
eld7","type":"oneLineText","page":1,&quo=
t;page_name":"Step
<br>
1","width":"100%"},{"label":"Commen=
ts","value":"some information about <br>
the <br>
compagny","identifier":"field5","type":&=
quot;textarea","page":1,"page_name":"Step <br=
>
1","width":"100%"}]<br>
<br>
<br>
# If you only need the width attribute, you can do this (no loop on the <br=
>
attributes needed):<br>
<br>
people.each_with_index do |person, i|<br>
puts "Person is #{i+1}" # First person displays =
as 1 instead of 0<br>
<br>
puts "The value of width is #{person[:width]}" if pe=
rson.has_key?(:width)<br>
end<br>
<br>
<br>
# If needed, loop through all the attributes of person (like in your <br>
example), but change to detecting symbol keys<br>
<br>
people.each_with_index do |person, i|<br>
puts "Person is #{i+1}" # First person is 1 inst=
ead of 0<br>
<br>
person.each do |key, value|<br>
if key =3D=3D :width<br>
puts "The value of width is #{val=
ue}"<br>
end<br>
end<br>
end<br>
<br>
<br>
Also, if you are defining your hashes, you don't need to use JSON format <b=
r>
with quoted keys, you can just do:<br>
<br>
a =3D {label: "Name", value: "Bob", identifier: "f=
ield2", type: <br>
"oneLineText", page: 1, page_name: "Step 1", width: &qu=
ot;100%"}<br>
<br>
<br>
Dan<br>
<br>
<br>
On 10/24/2019 1:35 AM, Tran, Minh wrote:<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>
</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_SN6PR05MB5391BA17FB6367196318534DEE790SN6PR05MB5391namp_--
--===============1647319645==
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>
--===============1647319645==--