Sorry, I wasn’t clear enough - my question is why does the call to
method2 from method1 fail with a
undefined method `method2’ for X:Module
Is the following what you are doing ?
irb(main):007:0> module X
irb(main):008:1> public
irb(main):009:1> def method1
irb(main):010:2> “method1” + method2
irb(main):011:2> end
irb(main):012:1> private
irb(main):013:1> def method2
irb(main):014:2> “method2”
irb(main):015:2> end
irb(main):016:1> end
=> nil
irb(main):017:0> class A
irb(main):018:1> include X
irb(main):019:1> end
=> A
irb(main):020:0> A.new.method1
---------------------^^^^^^^^^^---------------
irb(main):021:0> A.new.method1
=> “method1method2”
Because the above should work just fine. If the above is not what you
are seeing, please post the code so we can better help.
I just want to have some utility methods for use by my app.
The code below works.
Notice the calls to add_default_path in the other two methods.
My question is: why do I have to qualify the name of add_default_path
with ESimplyUtil since no external code is calling that method? Why
can’t I just have
def add_default_path
end
?
Thanks,
WG
===================
Here’s my module:
module ESimplyUtil
public
def ESimplyUtil.validate_and_format_url(in_url)
begin
url = URI.parse(in_url)
rescue
raise(“This is not a valid URL”)
end
#If the URL is valid HTTP URL, default the path if necessary
#If the URL is generic make it into an HTTP URL
# Get the host - match the first set of non-/ characters
# Get the path - match all of the characters including the first
slash #If the URL is a valid non-HTTP URL, then it’s an error.
if (url.instance_of?(URI::HTTP))
url = add_default_path(url)
elsif (url.instance_of?(URI::Generic))
if (((url.scheme != nil) && (url.scheme != “http”)) ||
(url.path.nil?) || (url.path == ‘’))
raise(“This is not a valid URL”)
else
port = 80
host = url.path.match(/[^/]+/)[0]
path_match = url.path.match(//(.*)/)
if (path_match.nil?)
path = ‘/’
else
path = path_match[0]
end