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 am still googling for a Ruby command that I could use to add my vendor folder to the LOAD_PATH.
···
________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Raj Sahae <rajsahae@gmail.com>
Sent: Wednesday, November 6, 2019 5:54 PM
To: Ruby users <ruby-talk@ruby-lang.org>
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 <minh.tran@emoryhealthcare.org<mailto:minh.tran@emoryhealthcare.org>> 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
________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org<mailto:ruby-talk-bounces@ruby-lang.org>> on behalf of Dan Fitzpatrick <dan@eparklabs.com<mailto:dan@eparklabs.com>>
Sent: Friday, October 25, 2019 12:30 AM
To: ruby-talk@ruby-lang.org<mailto:ruby-talk@ruby-lang.org> <ruby-talk@ruby-lang.org<mailto:ruby-talk@ruby-lang.org>>
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 =
{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step
1","width":"100%"}
=> {:label=>"Name", :value=>"Bob", :identifier=>"field2",
:type=>"oneLineText", :page=>1, :page_name=>"Step 1", :width=>"100%"}
b
={"label"=>"Name","value"=>"Bob","identifier"=>"field2","type"=>"oneLineText","page"=>1,"page_name"=>"Step
1","width"=>"100%"}
=> {"label"=>"Name", "value"=>"Bob", "identifier"=>"field2",
"type"=>"oneLineText", "page"=>1, "page_name"=>"Step 1", "width"=>"100%"}
a['width']
=> nil
b['width']
=> "100%"
a[:width]
=> "100%"
Here is your code working:
people =
[{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step
1","width":"100%"},{"label":"Email","value":"bob@compagny.com<mailto:bob@compagny.com>","identifier":"field3","type":"email","page":1,"page_name":"Step
1","width":"100%"},{"label":"Phone
Number","value":"","identifier":"field7","type":"oneLineText","page":1,"page_name":"Step
1","width":"100%"},{"label":"Comments","value":"some information about
the
compagny","identifier":"field5","type":"textarea","page":1,"page_name":"Step
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 == :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 = {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:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<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).