Calling instance method when module included

L

Leon Bogaert

Hi all,

Maybe a silly question, but is it possible to call instance methods on
an object when you've included a module? Or maybe I'm having the wrong
approach and somebody can point me in the right direction?

I'm now doing something like:

a = ['one', 'two', 'three']
a.send:)include, InstanceMethods)

And the InstanceMethods module looks like:

module InstanceMethods

def self.included(base)
base.instance_eval do
self.each do |item|
p item
end
end
end
end

Now I'm getting everytime: NoMethodError: undefined method `each' for
Array:Class

So my question: is a construction like this possible? If yes, how then?
If no: is there a better way to achieve this then? Or should I drop the
idea and first include the module and THEN create the object?

In this context it's maybe a bit silly, but I didn't want to post the
code in which I'm trying to use this construct because then it maybe
distracts from the idea I'm trying to achieve.

Thanks in advance all!
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top