module_function

P

Patrick Li

Hi,
I'm having some trouble using module_function correctly. If someone
could help me it'd be great.

I have a module M that defines method a().
I would like for a() to be callable by M.a() or include M; a();

However (and this is where my problem lies)
a() calls the helper method b().

module M
module_function
def a
b
end

private
def b
#helper method
end
end


This throws a NoMethodError when I try to call M.a(), because it looks
for M.b() (but there isn't and shouldn't be any).

What's the normal way for resolving this?
Thanks a lot for your help
-patrick
 
T

Trans

Hi,
I'm having some trouble using module_function correctly. If someone
could help me it'd be great.

I have a module M that defines method a().
I would like for a() to be callable by M.a() or include M; a();

However (and this is where my problem lies)
a() calls the helper method b().

module M
=A0 module_function
=A0 def a
=A0 =A0 b
=A0 end

=A0 private
=A0 def b
=A0 =A0 #helper method
=A0 end
end

This throws a NoMethodError when I try to call M.a(), because it looks
for M.b() (but there isn't and shouldn't be any).

What's the normal way for resolving this?

One way is to say, "to hell with module_function":

module M
extend self

def a
b
end

private
def b
#helper method
end
end

T.
 

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,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top