Hello,
I'm looking at URI class
http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html
The interface is somehow confusing?
I tried to write
url = uri.new
url.parse!('http://www.test.com')
but this give me error that new does not exist?
why cant I use it as a object? is the class static or is there something
i misunderstood?
In the doc they write that parse method raise URI::InvalidURIError
incase a url is incorrect typed.
when I try to use it, it doesn't work?
begin
#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
···
--
Posted via http://www.ruby-forum.com/.
Alle domenica 1 aprile 2007, Jamal Soueidan ha scritto:
Hello,
I'm looking at URI class
http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html
The interface is somehow confusing?
I tried to write
url = uri.new
url.parse!('http://www.test.com')
but this give me error that new does not exist?
why cant I use it as a object? is the class static or is there something
i misunderstood?
In the doc they write that parse method raise URI::InvalidURIError
incase a url is incorrect typed.
when I try to use it, it doesn't work?
begin
#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:
url=URI.parse('http://www.test.com')
I hope this helps
Stefano
To me it looks like "uri" doesn't exist:
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::<something> classes for each specific protocol like URI::HTTP and
the like.
irb(main):009:0> URI.parse("http://www.booger.com")
=> #<URI::HTTP:0xfdbe7c2fe URL:http://www.booger.com>
···
On Sun, 2007-01-04 at 20:42 +0900, Jamal Soueidan wrote:
I'm looking at URI class
http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html
The interface is somehow confusing?
I tried to write
url = uri.new
url.parse!('http://www.test.com')
but this give me error that new does not exist?
--
Michael T. Richter <ttmrichter@gmail.com> (GoogleTalk:
ttmrichter@gmail.com)
All really first class designers are both artists, engineers, and men of
a powerful and intolerant temper, quick to resist the least modification
of the plans, energetic in fighting the least infringement upon what
they regard as their own sphere of action. (Nevil Shute)
Well, where does it identify its module and not a class?
···
On 4/1/07, Stefano Crocco <stefano.crocco@alice.it> wrote:
Alle domenica 1 aprile 2007, Jamal Soueidan ha scritto:
> Hello,
>
> I'm looking at URI class
> http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html
>
> The interface is somehow confusing?
>
> I tried to write
> url = uri.new
> url.parse!('http://www.test.com')
>
> but this give me error that new does not exist?
> why cant I use it as a object? is the class static or is there something
> i misunderstood?
>
> In the doc they write that parse method raise URI::InvalidURIError
> incase a url is incorrect typed.
>
> when I try to use it, it doesn't work?
>
> begin
> #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:
url=URI.parse('http://www.test.com')
I hope this helps
Stefano
Yes I understand that its module now 
But how can I see its module, I can see this:
Module URI::Escape<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Escape.html>
Module URI::REGEXP<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/REGEXP.html>
Class URI::BadURIError<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/BadURIError.html>
Class URI::Error<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Error.html>
Class URI::FTP<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/FTP.html>
Class URI::Generic<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Generic.html>
Class URI::HTTP<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/HTTP.html>
Class URI::HTTPS<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/HTTPS.html>
Class URI::InvalidComponentError<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/InvalidComponentError.html>
Class URI::InvalidURIError<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/InvalidURIError.html>
Class URI::LDAP<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/LDAP.html>
Class URI::MailTo<http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/MailTo.html>
I thought I would use URI:HTTP ?
Another little thing is it does not throw any exceptions as mentioned in the
doc?
···
On 4/1/07, Michael T. Richter <ttmrichter@gmail.com> wrote:
On Sun, 2007-01-04 at 20:42 +0900, Jamal Soueidan wrote:
I'm looking at URI classhttp://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html
The interface is somehow confusing?
I tried to writeurl = uri.newurl.parse!('http://www.test.com')
but this give me error that new does not exist?
To me it looks like "uri" doesn't exist:
irb(main):007:0> require 'uri'=> trueirb(main):008:0> url = uri.newNameError: 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::<something> classes for each
specific protocol like URI::HTTP and the like.
irb(main):009:0> URI.parse("http://www.booger.com")=> #<URI::HTTP:0xfdbe7c2fe URL:http://www.booger.com>
--
*Michael T. Richter* <ttmrichter@gmail.com> (*GoogleTalk:*
ttmrichter@gmail.com)
*All really first class designers are both artists, engineers, and men of
a powerful and intolerant temper, quick to resist the least modification of
the plans, energetic in fighting the least infringement upon what they
regard as their own sphere of action. (Nevil Shute)*
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:
irb: 001> require 'uri'
true
irb: 002> URI.class
Module
irb: 003>
I hope this helps
Stefano
Stefano Crocco wrote:
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:
irb: 001> require 'uri'
true
irb: 002> URI.class
Module
irb: 003>
I hope this helps
Stefano
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?
···
--
Posted via http://www.ruby-forum.com/\.
Alle domenica 1 aprile 2007, Jamal Soueidan ha scritto:
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.
I hope this helps
Stefano
Stefano Crocco wrote:
Alle domenica 1 aprile 2007, Jamal Soueidan ha scritto:
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?
···
--
Posted via http://www.ruby-forum.com/\.
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?
···
--
Posted via http://www.ruby-forum.com/\.
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.
···
On Apr 1, 2007, at 6:42 PM, Jamal Soueidan wrote:
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?
Gary Wright wrote:
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
* Scheme
* Userinfo
* Host
* Port
* Registry
* Path
* Opaque
* Query
* Fragment
···
On Apr 1, 2007, at 6:42 PM, Jamal Soueidan wrote:
--
Posted via http://www.ruby-forum.com/\.
Jamal Soueidan wrote:
Gary Wright wrote:
I also see that split return an array of the following parts
* Scheme
* Userinfo
* Host
* Port
* Registry
* Path
* Opaque
* Query
* Fragment
url = URI::split(url)
p url.host
This doesn't work, host method not found?
···
--
Posted via http://www.ruby-forum.com/\.
Jamal Soueidan wrote:
Jamal Soueidan wrote:
> I also see that split return an array of the following parts
>
> * Scheme
> * Userinfo
> * Host
> * Port
> * Registry
> * Path
> * Opaque
> * Query
> * Fragment
url = URI::split(url)
p url.host
This doesn't work, host method not found?
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
···
--
NP: In Flames - Satellites And Astronauts
Ist so, weil ist so
Bleibt so, weil war so
Sebastian Hungerecker wrote:
Jamal Soueidan wrote:
> * Query
> * Fragment
url = URI::split(url)
p url.host
This doesn't work, host method not found?
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?
so it be more readable like this 
uri.host 
···
--
Posted via http://www.ruby-forum.com/\.
Sebastian Hungerecker wrote:
Jamal Soueidan wrote:
* Query
* Fragment
url = URI::split(url)
p url.host
This doesn't work, host method not found?
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?
so it be more readable like this 
uri.host 
You don't need the split() method to get this syntax:
>> require "uri"
=> false
>> uri = URI.parse("http://www.ruby-lang.org")
=> #<URI::HTTP:0xa77416 URL:http://www.ruby-lang.org>
>> uri.host
=> "www.ruby-lang.org"
James Edward Gray II
···
On Apr 2, 2007, at 6:19 AM, Jamal Soueidan wrote:
Thanks everyone for help 
I appropriated all the help 
···
--
Posted via http://www.ruby-forum.com/.