Ruby include module's single method in model

Viewed 8826

I have a module of following

module SimpleTask
    def task1
    end
    def task2
    end
    def task3
    end
end

And I have a model which requires only task2 method of module SimpleTask.

I know including SimpleTask in my model with include SimpleTask would do the job.

But I wonder if I can only include specific task2 method in my model.

4 Answers

A simple solution for this is

define_method :task2, SimpleTask.instance_method(:task2)

Related