I have a module which declares a number of instance methods
module UsefulThings
def get_file; ...
def delete_file; ...
def format_text(x); ...
end
And I want to call some of these methods from within a class. How you normally do this in ruby is like this:
class UsefulWorker
include UsefulThings
def do_work
format_text("abc")
...
end
end
include UsefulThings
brings in all of the methods from UsefulThings
. In this case I only want format_text
and explicitly do not want get_file
and delete_file
.
I can see several possible solutions to this:
Usefulthings
and only bring in some of it's methods
UsefulThings
in that, then delegate format_text
to that proxy instance
Why are there lots of unrelated functions in a single module? It's ApplicationHelper
from a rails app, which our team has de-facto decided on as the dumping ground for anything not specific enough to belong anywhere else. Mostly standalone utility methods that get used everywhere. I could break it up into seperate helpers, but there'd be 30 of them, all with 1 method each... this seems unproductive
I think the shortest way to do just throw-away single call (without altering existing modules or creating new ones) would be as follows:
Class.new.extend(UsefulThings).get_file