From: Wes Gamble Date: 2006-04-29T01:29:43+09:00 Subject: Re: Intra-module method calls 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 url = URI::HTTP.new('http', nil, host, 80, nil, path, nil, nil, nil) end elsif (! url.instance_of?(URI::HTTP)) raise("This is not a valid URL") end url end public def ESimplyUtil.get_URL(myURL) url = URI.parse(myURL) url = add_default_path(url) req = Net::HTTP::Get.new(url.path) res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) } res end private def ESimplyUtil.add_default_path(url) if ((url.path == '') || (url.path.nil?)) url.path = '/' end url end end -- Posted via http://www.ruby-forum.com/.