Calling Ruby module methods from a nested class within

M

mgerstenblatt

Hi, Is there an alternative to calling a Module method from a nested
class? The code:

module GroupSweeper


=A0 def expire_cache(paths)

=A0 =A0 paths.each do |path|

=A0 =A0 =A0 expire_page(path)

=A0 =A0 end

=A0 end


=A0 class SweeperOne < ActionController::Caching::Sweeper

=A0 =A0 include GroupSweeper

=A0 =A0 observe Subject

=A0 =A0 def after_save(subject)

=A0 =A0 =A0 expire_cache([root_path,subjects_path])

=A0 =A0 end

=A0 =A0 def after_destroy(subject)

=A0 =A0 =A0 expire_cache([root_path,subjects_path])

=A0 =A0 end

=A0 end


end

How can I call GroupSweeper's expire_cache method from within
SweeperOne without explicitely including it? Should I not be doing
this?
 
G

Gunther Diemant

[Note: parts of this message were removed to make it a legal post.]

Afaik there is no way to call an instance method of a module without
including it (or extending an Object with it).
But you can make expire_cache a module class method and then call it.

module GroupSweeper
def self.expire_cache(paths)
puts "dummy code"
end
end

class Foo < Bar
def baz(arg)
GroupSweeper.expire_cache(arg)
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top