Can we reference an array from one ruby script to another and access array elements?
for example : my first rb file
$joe = "one"
$po = "two"
$so = "three"
names = [ $joe, $po, $so ]
second rb file
require "1"
$trial = names[1]
puts $trial
But this didn't work.
You can do it like this ( Ruby 1.9 ):
1.rb:
module Whatever
@names = ["one","two","three"]
def self.names
@names
end
end
2.rb:
require_relative "1"
Whatever.names.each {|n| puts n}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With