I guess I was not clear. I am trying to place a class method in a module
and include it in the class. I am not trying to instantiate an instance
of a class and and include the method from the module in the instance,
which, if I am reading your reference correctly, is what extend does.
Note that I am very new to Ruby so I may be missing something. Thanks.
Thanks. That works but the method in the module does not have access to
class variables. Is there any way to give the method in the module
access to class variables?
That works but the method in the module does not have access to class
variables. Is there any way to give the method in the module access to
class variables?
Thanks. That works but the method in the module does not have access to
class variables. Is there any way to give the method in the module
access to class variables?
Which class variable do you mean?
module FtpClientMod @foo = 1
@@bar = 1
def do_send(file_template, show_progress)
puts “do_send #{file_template} #@foo #@@bar #{gimme_bar}”
end
def gimme_bar
@@bar
end
end
class FtpClient @foo = 2
@@bar = 2
class << self @foo = 3
include FtpClientMod
def gimme_bar
@@bar
end
end
end
FtpClient.do_send(‘foo’, 0)
=> do_send foo 2 1 2
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.