Hello,
This is my question:
I need to execute the same piece of code in several different .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 invoke it in one of my files
like this:
require ‘shared_classes.rb’
module Module1
class Class1
def initialize()
Shared_classes::Getfiles.new() # Invoke code from external file
puts list_clean[0] ==> Error # Try to use the variable
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
I was expecting that the result of shared_classes.rb (list_clean) could
be used in my file. But not.
How can I use values from variables from external .rb files?
Thnx