How to include/require/load a file in ruby with instance variables

Posted by doctororange on Stack Overflow See other posts from Stack Overflow or by doctororange
Published on 2010-03-13T09:29:56Z Indexed on 2010/03/13 9:35 UTC
Read the original article Hit count: 317

Filed under:
|
|

I would like to put a large variable definition in a separate file for the sake of getting it out of the way. I must be doing something wrong though, because my puts call isn't putting anything out.

my_class.rb:

class foobar
  def initialize
    require 'datafile.rb'
    puts @fat_data
  end
end

datafile.rb:

@fat_data = [1,2,3,4,5,6,7,8,9,10]

Can you use require this way?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about require