How to compare a hash key with a string value

Hello,
    I am having a scenario which I want to print out the value of a hash element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash = [{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step 1","width":"100%"},{"label":"Email","value":"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%"}]

My Ruby code is as the following where I need to print out the hash value when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|

    if key == "width"
      puts "The value of width is #{value}"
    end

  end
end

Thanks in advance for all of the helps.
Dun

···

________________________________

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).

I am not 100% clear on the question, but you could possibly just do
something like this?

hash.each_with_index do |person, i|
puts "Person is #{i}"

if person.has_key?('width')
   puts "The value of width is #{person['width']}"
end

end

···

On Wed, Oct 23, 2019 at 10:36 AM Tran, Minh <minh.tran@emoryhealthcare.org> wrote:

Hello,
    I am having a scenario which I want to print out the value of a hash
element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash =
[{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step
1","width":"100%"},{"label":"Email","value":"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%"}]

My Ruby code is as the following where I need to print out the hash value
when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|

    if key == "width"
      puts "The value of width is #{value}"
    end

  end
end

Thanks in advance for all of the helps.
Dun

------------------------------

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:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

I don't see a Person class or object defined anywhere...

···

On Wed, 23 Oct 2019 at 10:36, Tran, Minh <minh.tran@emoryhealthcare.org> wrote:

Hello,
    I am having a scenario which I want to print out the value of a hash
element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash =
[{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step
1","width":"100%"},{"label":"Email","value":"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%"}]

My Ruby code is as the following where I need to print out the hash value
when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|

    if key == "width"
      puts "The value of width is #{value}"
    end

  end
end

Thanks in advance for all of the helps.
Dun

------------------------------

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:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--
Regards,

Ken

Seek wisdom through disbelief

Thank you so much Jonathan for all of the helps.
I tried your code and it gave me the person number such as
person 1 , person 2, ete; but it does not give me the value of the
person.has_key?('width') on each of the person.

I still try to figure out why it did not execute this piece of code

if person.has_key?('width')

   puts "The value of width is #{person['width']}"

end

My original program is as followed:

hash = [{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step 1","width":"100%"},{"label":"Email","value":"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%"}]

hash.each_with_index do |person, i|

puts "Person is #{i}"

if person.has_key?('width')

   puts "The value of width is #{person['width']}"

end

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Jonathan Fagan <jfagan365@gmail.com>
Sent: Wednesday, October 23, 2019 1:48 PM
To: Ruby users <ruby-talk@ruby-lang.org>
Subject: [External] Re: How to compare a hash key with a string value

I am not 100% clear on the question, but you could possibly just do something like this?

hash.each_with_index do |person, i|
puts "Person is #{i}"

if person.has_key?('width')
   puts "The value of width is #{person['width']}"
end

end

On Wed, Oct 23, 2019 at 10:36 AM Tran, Minh <minh.tran@emoryhealthcare.org<mailto:minh.tran@emoryhealthcare.org>> wrote:
Hello,
    I am having a scenario which I want to print out the value of a hash element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash = [{"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%"}]

My Ruby code is as the following where I need to print out the hash value when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|

    if key == "width"
      puts "The value of width is #{value}"
    end

  end
end

Thanks in advance for all of the helps.
Dun

________________________________

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).

I think I see your problem, Minh.

Your hashes (elements of your array of hashes, actually), seems to be in JSON format and doesn't produce the Ruby Hash with the keys that you expect.

{"label":"Name"} is the same as { :label => "Name" } because the Ruby syntax for a Hash literal looks like {key: value} where the key is always a symbol. It is also true that :"key" is an alternate way of defining a Symbol literal.

If you change your loop to be:

hash.each.with_index(1) do |person,i|
  puts "Person is #{i}"
  if person.key? :width
    puts "The value of width is #{person[:width]}"
  end
end

I think that you'll get the result that you were expecting.

Alternatively, you could replace the Hash literal syntax with:

hash = [{"label" => "Name","value" => "Bob","identifier" => "field2","type" => "oneLineText","page" => 1,"page_name" => "Step 1","width" => "100%"},
        {"label" => "Email","value" => "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%"},
       ]

And your original code that expected keys that were Strings would work.

-Rob

···

On 2019-Oct-23, at 14:01 , Tran, Minh <minh.tran@emoryhealthcare.org> wrote:

Thank you so much Jonathan for all of the helps.
I tried your code and it gave me the person number such as
person 1 , person 2, ete; but it does not give me the value of the
person.has_key?('width') on each of the person.

I still try to figure out why it did not execute this piece of code

if person.has_key?('width')

   puts "The value of width is #{person['width']}"

end

My original program is as followed:

hash = [{"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%"}]

hash.each_with_index do |person, i|

puts "Person is #{i}"

if person.has_key?('width')

   puts "The value of width is #{person['width']}"

end

From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Jonathan Fagan <jfagan365@gmail.com>
Sent: Wednesday, October 23, 2019 1:48 PM
To: Ruby users <ruby-talk@ruby-lang.org>
Subject: [External] Re: How to compare a hash key with a string value

I am not 100% clear on the question, but you could possibly just do something like this?

hash.each_with_index do |person, i|
puts "Person is #{i}"

if person.has_key?('width')
   puts "The value of width is #{person['width']}"
end

end

On Wed, Oct 23, 2019 at 10:36 AM Tran, Minh <minh.tran@emoryhealthcare.org <mailto:minh.tran@emoryhealthcare.org>> wrote:
Hello,
    I am having a scenario which I want to print out the value of a hash element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash = [{"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%"}]

My Ruby code is as the following where I need to print out the hash value when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|
   
    if key == "width"
      puts "The value of width is #{value}"
    end
    
  end
end

Thanks in advance for all of the helps.
Dun

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:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Thank you so much Rob for all of the helps.
Yes, it works and I learn a lot from you and other members more on Ruby syntax for the hash.
Regards,
Minh

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Rob Biedenharn <rob.biedenharn@gmail.com>
Sent: Wednesday, October 23, 2019 2:28 PM
To: Ruby users <ruby-talk@ruby-lang.org>
Subject: Re: [External] How to compare a hash key with a string value

I think I see your problem, Minh.

Your hashes (elements of your array of hashes, actually), seems to be in JSON format and doesn't produce the Ruby Hash with the keys that you expect.

{"label":"Name"} is the same as { :label => "Name" } because the Ruby syntax for a Hash literal looks like {key: value} where the key is always a symbol. It is also true that :"key" is an alternate way of defining a Symbol literal.

If you change your loop to be:

hash.each.with_index(1) do |person,i|
  puts "Person is #{i}"
  if person.key? :width
    puts "The value of width is #{person[:width]}"
  end
end

I think that you'll get the result that you were expecting.

Alternatively, you could replace the Hash literal syntax with:

hash = [{"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%"},
       ]

And your original code that expected keys that were Strings would work.

-Rob

On 2019-Oct-23, at 14:01 , Tran, Minh <minh.tran@emoryhealthcare.org<mailto:minh.tran@emoryhealthcare.org>> wrote:

Thank you so much Jonathan for all of the helps.
I tried your code and it gave me the person number such as
person 1 , person 2, ete; but it does not give me the value of the
person.has_key?('width') on each of the person.

I still try to figure out why it did not execute this piece of code

if person.has_key?('width')

   puts "The value of width is #{person['width']}"

end

My original program is as followed:

hash = [{"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%"}]

hash.each_with_index do |person, i|

puts "Person is #{i}"

if person.has_key?('width')

   puts "The value of width is #{person['width']}"

end

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org<mailto:ruby-talk-bounces@ruby-lang.org>> on behalf of Jonathan Fagan <jfagan365@gmail.com<mailto:jfagan365@gmail.com>>
Sent: Wednesday, October 23, 2019 1:48 PM
To: Ruby users <ruby-talk@ruby-lang.org<mailto:ruby-talk@ruby-lang.org>>
Subject: [External] Re: How to compare a hash key with a string value

I am not 100% clear on the question, but you could possibly just do something like this?

hash.each_with_index do |person, i|
puts "Person is #{i}"

if person.has_key?('width')
   puts "The value of width is #{person['width']}"
end

end

On Wed, Oct 23, 2019 at 10:36 AM Tran, Minh <minh.tran@emoryhealthcare.org<mailto:minh.tran@emoryhealthcare.org>> wrote:
Hello,
    I am having a scenario which I want to print out the value of a hash element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash = [{"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%"}]

My Ruby code is as the following where I need to print out the hash value when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|

    if key == "width"
      puts "The value of width is #{value}"
    end

  end
end

Thanks in advance for all of the helps.
Dun

________________________________

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:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

A few remarks inline below.

Hello,
    I am having a scenario which I want to print out the value of a hash
element when its key equals to a string value such as "width".
I try several alternatives but so far I have had a good result.
So if you know on how to do , please share it with me.

My hash table array looks like as the following:

hash =
[{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step
1","width":"100%"},{"label":"Email","value":"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%"}]

The name of the variable is misleading. This is actually an Array of Hash,
so "hashes" would be more appropriate.

My Ruby code is as the following where I need to print out the hash value
when the hash key equals to "width"

i = 0
hash.each do |person|
i += 1
puts "Person is #{i}"
person.each do |key, value|

You are not actually using the Hash as a hashtable with fast lookups here.

    if key == "width"
      puts "The value of width is #{value}"
    end

  end
end

I would do

hashes.each_with_index do |h, i|
  puts "Person: #{i}"
  width = h["width"] and puts "The value of width is #{width}"
end

This is more efficient than checking with #has_key? because it requires
just a single hash lookup vs. two. If you want a printout also for nil and
false you could do

hashes.each_with_index do |h, i|
  puts "Person: #{i}"
  match = h.assoc(:width) and puts "The value of width is #{match.last}"
end

Cheers

robert

···

On Wed, Oct 23, 2019 at 7:36 PM Tran, Minh <minh.tran@emoryhealthcare.org> 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 <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).

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 <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

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 <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
Sent: Thursday, November 7, 2019 12:16 PM
To: Ruby users <ruby-talk@ruby-lang.org>
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 <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

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).

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__)

=> ["/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'
=> 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 <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:16 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*Subject:* Re: [External] re: Adding a directory to LOAD_PATH
Have you tried something like:

  $LOAD\_PATH &lt;&lt; File\.expand\_path\(&quot;\.\./my\_project/&quot;, \_\_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 <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 &quot;Hello World\!&quot;
 require File\.join \(File\.expand\_path \(File\.dirname\(\_\_FILE\_\_\)\),
 &#39;vendor/kinectic\-sdk\-rb/kinectic\-sdk\.rb&#39;\)

 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: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).

Thank you so much Liam for showing me on how to run my test in the live Ruby environment.
Minh

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
Sent: Thursday, November 7, 2019 12:53 PM
To: Ruby users <ruby-talk@ruby-lang.org>
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__)

=> ["/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'
=> 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 <ruby-talk-bounces@ruby-lang.org> on behalf of Leam
Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:16 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*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 <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

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).

I got an error message when I tried to use LOAD_PATH. I would like to seek your helps and expertise.

Thanks!

ruby -e '$LOAD_PATH << FILE.expand_path ("/vendor/kinectic-sdk-rb",__FILE__)'

- syntax error, unexpected ( arg, expecting end-of-input
...LOAD_PATH << FILE.expand_path ("vendor/kinectic..

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
Sent: Thursday, November 7, 2019 12:53 PM
To: Ruby users <ruby-talk@ruby-lang.org>
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__)

=> ["/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'
=> 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 <ruby-talk-bounces@ruby-lang.org> on behalf of Leam
Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:16 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*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 <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

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).

Try putting ".." before "/vendor", do not have a space between "expand_path" and the "(", and use File.expand_path instead of FILE.expand_path.

This worked for me:

    ruby -e '$LOAD_PATH << File.expand_path("../lib/", __FILE__)'

Leam

···

On 11/7/19 1:46 PM, Tran, Minh wrote:

I got an error message when I tried to use LOAD_PATH. I would like to seek your helps and expertise.

Thanks!

ruby -e '$LOAD_PATH << FILE.expand_path ("/vendor/kinectic-sdk-rb",__FILE__)'

- syntax error, unexpected ( arg, expecting end-of-input
...LOAD_PATH << FILE.expand_path ("vendor/kinectic..

------------------------------------------------------------------------
*From:* ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:53 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*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__)

=> ["/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'
=> 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 <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:16 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*Subject:* Re: [External] re: Adding a directory to LOAD_PATH
Have you tried something like:

   $LOAD\_PATH &lt;&lt; File\.expand\_path\(&quot;\.\./my\_project/&quot;, \_\_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 <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 &quot;Hello World\!&quot;
 require File\.join \(File\.expand\_path \(File\.dirname\(\_\_FILE\_\_\)\),
 &#39;vendor/kinectic\-sdk\-rb/kinectic\-sdk\.rb&#39;\)

 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: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).

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Thank you so much Leam for all of the helps. It works.
Regards,
Minh

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Leam Hall <leamhall@gmail.com>
Sent: Thursday, November 7, 2019 1:52 PM
To: Ruby users <ruby-talk@ruby-lang.org>
Subject: Re: [External] re: Adding a directory to LOAD_PATH

Try putting ".." before "/vendor", do not have a space between
"expand_path" and the "(", and use File.expand_path instead of
FILE.expand_path.

This worked for me:

    ruby -e '$LOAD_PATH << File.expand_path("../lib/", __FILE__)'

Leam

On 11/7/19 1:46 PM, Tran, Minh wrote:

I got an error message when I tried to use LOAD_PATH. I would like to
seek your helps and expertise.

Thanks!

ruby -e '$LOAD_PATH << FILE.expand_path
("/vendor/kinectic-sdk-rb",__FILE__)'

- syntax error, unexpected ( arg, expecting end-of-input
...LOAD_PATH << FILE.expand_path ("vendor/kinectic..

------------------------------------------------------------------------
*From:* ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Leam
Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:53 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*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__)

=> ["/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'
=> 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 <ruby-talk-bounces@ruby-lang.org> on behalf of Leam
Hall <leamhall@gmail.com>
*Sent:* Thursday, November 7, 2019 12:16 PM
*To:* Ruby users <ruby-talk@ruby-lang.org>
*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 <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

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).

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

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.rb" then you want only /vendor in your
$LOAD_PATH, not /vendor/kinetic-sdk-rb - 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"
=> ["/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", "/usr/lib/ruby/2.5.0",
"/usr/lib/x86_64-linux-gnu/ruby/2.5.0", "/tmp/ruby"]
irb(main):002:0> require 'foo/bar'
=> true
irb(main):003:0> f
hello world

martin

···

On Thu, Nov 7, 2019 at 9:42 AM Tran, Minh <minh.tran@emoryhealthcare.org> 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__)

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

···

________________________________
From: ruby-talk <ruby-talk-bounces@ruby-lang.org> on behalf of Martin DeMello <martindemello@gmail.com>
Sent: Thursday, November 7, 2019 2:33 PM
To: Ruby users <ruby-talk@ruby-lang.org>
Subject: Re: [External] re: Adding a directory to LOAD_PATH

On Thu, Nov 7, 2019 at 9:42 AM Tran, Minh <minh.tran@emoryhealthcare.org<mailto:minh.tran@emoryhealthcare.org>> 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.rb" then you want only /vendor in your $LOAD_PATH, not /vendor/kinetic-sdk-rb - 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"
=> ["/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", "/usr/lib/ruby/2.5.0", "/usr/lib/x86_64-linux-gnu/ruby/2.5.0", "/tmp/ruby"]
irb(main):002:0> require 'foo/bar'
=> 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).