Best way to create a helper method

What would you guys say is the best way of creating a helper method?

module MyModule
def myMethod
#bla bla
end
end

def helperMethod
#a helper method whose existence should not be known outside of this
file
end

helperMethod() shouldn’t be visible from anywhere outside this file.

Thanks for helping me with this
-Patrick

Patrick Li wrote:

file
end

helperMethod() shouldn’t be visible from anywhere outside this file.

Can you put helperMethod inside MyModule, and make it private? I don’t
know if
the language supports that.

And you may want to consider unit tests as more important than static
type
checking, to keep a program on track…

I can:

module MyModule
def myMethod
#bla bla
end

private
def helperMethod
#a helper method whose existence should not be known outside of this
file
end
end

But I can still get access to helperMethod by mixing in the module.

eg.
class MyClass
include MyModule #I want myMethod() but not helperMethod()
end

Thanks for replying
-Patrick

But I can still get access to helperMethod by mixing in the module.

protected ?

Patrick Li wrote:

But I can still get access to helperMethod by mixing in the module.

Private methods are not a form of code security. Even if you made this
method
completely private, you can still get to it with .send(:helperMethod).

No language makes any private method absolutely private. You should
think of
privacy as nothing more than a warning - “please reconsider calling this
method”. Another common way to do that is move the method out of the
default
namespace by calling it _helperMethod.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs