Can we reference an array from one ruby script to another and access array elements?
for example : my first rb file
1.rb
$joe = "one"
$po = "two"
$so = "three"
names = [ $joe, $po, $so ]
second rb file
2.rb
require "1"
$trial = names[1]
puts $trial
But this didn’t work.
You could set
namesas a global variable, though I’d only recommend it if this is a small script. Else, aModuleis the way to go, like in @Tempus’s answer.Example:
1.rb:2.rb: