#code
rescue URI::InvalidURIError
p “wrong url” #this never happens even if the uri is empty?
end
Thanks for your time and effort
Regards,
Jamal
URI is a module, not a class, so it doesn’t have a new method (you can’t
create instances of a module). I’ve never used URI, so I can’t be sure,
but,
according to the documentation, you should do:
irb(main):007:0> require ‘uri’
=> true
irb(main):008:0> url = uri.new
NameError: undefined local variable or method `uri’ for main:Object
from (irb):8
from /usr/lib/ruby/1.8/uri/http.rb:56
Glancing at the page you posted, I see there that there is no object
called “uri” anywhere. There is a module called “URI” and it has a
parse method, but there isn’t a class you can instantiate. What’s
returned from that method (there also doesn’t appear to be a “parse!”
method anywhere on that page) looks like it’s one of the
URI:: classes for each specific protocol like URI::HTTP and
the like.
Alle domenica 1 aprile 2007, Yamal Soueidan ha scritto:
Well, where does it identify its module and not a class?
If you look at the documentation page you mentioned
(http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html), you see it
says: “See URI for documentation”. Clicking on the link (the work URI),
you
reach the documentation page for the URI module. There, at the left of
the
title (URI), there’s written ‘module’. This tells you URI is not a class
but
a module. An other way is to use irb:
Alle domenica 1 aprile 2007, Yamal Soueidan ha scritto:
Well, where does it identify its module and not a class?
If you look at the documentation page you mentioned
(http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html), you see it
says: “See URI for documentation”. Clicking on the link (the work URI),
you
reach the documentation page for the URI module. There, at the left of
the
title (URI), there’s written ‘module’. This tells you URI is not a class
but
a module. An other way is to use irb:
Thanks, but as I can see there is some methods there:
section
Classes and Modules under the module URI documentation. The methods you
mentioned (host, port) are instance methods of these classes. All the
classes
I hope this helps
Stefano
That was great help to understand that, but I still think the
documentation library is bad, I come from PHP world and the
documentation is very great with all sort of examples and comments from
people?
Thanks, but as I can see there is some methods there:
extract  join  parse  regexp  split
what about the attributes which I can access like
url.host or url.port ?
I don’t see they mention them on that page?
This is because they’re not methods of the URI module, but of classes
declared
in it. The URI module knows about several kinds of URIs (from the
documentation, they’re http, https, ftp, ldap and mailto). If the string
you
pass to URI.parse corresponds to one of these types, then parse returns
an
instance of the appropriate class. Otherwise, it will return an instance
of
class URI::Generic. To see which classes are availlable, look at the
section
Classes and Modules under the module URI documentation. The methods you
mentioned (host, port) are instance methods of these classes. All the
classes
used to represent URIs are derived from URI::Generic, so it’s likely
that
behaviour which doesn’t depend on the kind of URI will be there. You
should
look under the Methods and the Attributes sections of the documentation
page
(for example, host and port are both listed under attributes). If you
need to
use something which is specific to a kind of URI, instead, you should
look at
the documentation for the class which specifically represents that kind
of
URI.
If the string you pass to URI.parse corresponds to one of these types, then
parse returns an instance of the appropriate class. Otherwise, it will return an
instance of class URI::Generic
I wonder actually how you knew that it will return one of these types
and why do you think it will return Generic?
Since I cannot find anything related to these information on the
documentation page?
If the string you pass to URI.parse corresponds to one of these
types, then
parse returns an instance of the appropriate class. Otherwise, it
will return an
instance of class URI::Generic
I wonder actually how you knew that it will return one of these types
and why do you think it will return Generic?
In the description of URI.parse it says:
Creates one of the URI‘s subclasses instance from the string
If the string you pass to URI.parse corresponds to one of these
types, then
parse returns an instance of the appropriate class. Otherwise, it
will return an
instance of class URI::Generic
I wonder actually how you knew that it will return one of these types
and why do you think it will return Generic?
In the description of URI.parse it says:
Creates one of the URI�s subclasses instance from the string
The documentation is quite sparse for URI.
I also see that split return an array of the following parts
Well, as you said, the split method returns an array. Arrays have no
method
called host, so that’s what ruby tells you.
You’d access the host with url[2] because it’s the third element in the
array.
Well, as you said, the split method returns an array. Arrays have no
method
called host, so that’s what ruby tells you.
You’d access the host with url[2] because it’s the third element in the
array.
HTH,
Sebastian
Ok I got that, why not use hash then if they tell us you got that in
return?