I am trying to pass an array to a ruby script from a command line and facing some issue.
Here is the problem:
require 'pp'
def foo(arr1, var, arr2, var2)
puts arr1.class
pp arr1
pp arr1[0]
puts arr2.class
pp arr2
pp arr2[0]
end
foo [1, 2], 3, [5, 6], 8
Here is the output:
Array
[1, 2]
1
Array
[5, 6]
5
All is fine so far. Now I change my script to accept argument from the command line:
require 'pp'
def foo(arr1,var)
puts arr1.class
pp arr1
pp arr1[0]
end
foo ARGV[0],3
Here is the output:
jruby test.rb [1, 2], 3, [5, 6], 8
String
"[1,"
91
String
"2],"
50
As you can see, the array gets passed as a string and arr[0] basically prints the ascii value.
So the question is how do I pass an array from the command line , hopefully in one line. Also I believe this question is related to all shell invocations than just ruby ?
I am using bash shell.
Update: Just updated the question to indicate that there can be multiple arrays at different positions