I have a two part question
Best-Practice
These are the options I can see, which is the best?:
Technical part
Is there any way to make a private Module method?
module Thing
def self.pub; puts "Public method"; end
private
def self.priv; puts "Private method"; end
end
The private
in there doesn't seem to have any effect, I can still call Thing.priv
without issue.
I think the best way (and mostly how existing libs are written) to do this is by creating a class within the module that deals with all the logic, and the module just provides a convenient method, e.g.
module GTranslate
class Translator
def perform( text ); translate( text ); end
private
def translate( text )
# do some private stuff here
end
end
def self.translate( text )
t = Translator.new
t.perform( text )
end
end