From: "Jesús Gabriel y Galán" Date: 2012-01-24T00:33:23+09:00 Subject: Re: use external .rb file On Mon, Jan 23, 2012 at 2:18 PM, Ronnie Aa wrote: > Hello, > > > > This is my question: > > > I need to execute the same piece of code in several rb files. > I don't want to write it over and over again, so I choose to put that > piece of code in an external .rb file and call it in my file like this: > > > > require 'shared_classes.rb' > > > module Module1 >  class Class1 >    def initialize() >      Shared_classes::Getfiles.new() >      puts list_clean[0] >    end >  end > end > > > > > > This is the external file called 'shared_classes.rb' : > > > > > module Shared_classes >  class Getfiles >    def initialize() >      Dir.chdir("C:\\Directory\\") >      d = Dir.getwd >      listing = Dir.entries(d) >      list_clean  = [] >      listing.each { |e| >          if File.ctime(e).to_i > 1326718641  # Get all the newer files >            list_clean = list_clean.push(e) >          end >           } > > >    end >  end > end > > > > Like this the code doesn't work, the variable 'list_clean' is not > transferred... // picked up by my file.. > How do I solve this?? I guess you want list_clean to be an attribute of the class no a local variable of the initialize method: class Getfiles attr_reader :list_clean def initialize [...] @list_clean = [] [...] end end And from the other class: module Module1 class Class1 def initialize shared = Shared_classes::Getfiles.new() puts shared.list_clean[0] end end end Jesus.