Search code examples
rubyirb

accessing variables in loaded source while in irb


Say I have a file named test1.rb with the following code:

my_array = [1, 2, 3, 4 5]

Then I run irb and get an irb prompt and run "require 'test1'. At this point I am expecting to be able to access my_array. But if I try to do something like...

puts my_array

irb tells me "my_array" is undefined. Is there a way to access "my_array"


Solution

  • like this:

    def my_array
        [1, 2, 3, 4, 5]
    end