[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Given a class, what is the 'require' line?

Swaroop C H

7/1/2007 2:16:00 PM

Hi all,

If there's a class StringScanner, I run 'ri StringScanner' and read
the documentation on how to use it, but nowhere it mentions the
'require' line needed, how do we usually find it out? I had to google
to find out that `require 'strscan'` is the line needed...

When I asked about this on IRC, they said run ` egrep -r
'StringScanner' /usr/lib/ruby/1.8`, but I was really hoping there's a
builtin way of doing it.

Thanks,
Swaroop
--
ion | power your music
Get your own ion right now at www.ion.co.in !

10 Answers

Stefano Crocco

7/1/2007 2:30:00 PM

0

Alle domenica 1 luglio 2007, Swaroop C H ha scritto:
> Hi all,
>
> If there's a class StringScanner, I run 'ri StringScanner' and read
> the documentation on how to use it, but nowhere it mentions the
> 'require' line needed, how do we usually find it out? I had to google
> to find out that `require 'strscan'` is the line needed...
>
> When I asked about this on IRC, they said run ` egrep -r
> 'StringScanner' /usr/lib/ruby/1.8`, but I was really hoping there's a
> builtin way of doing it.
>
> Thanks,
> Swaroop

You can look at the online documentation (http://www.ruby-doc...) and
at the standard library reference (http://www.ruby-doc.o...).

I hope this helps

Stefano

Stefan Rusterholz

7/1/2007 2:31:00 PM

0

Swaroop C H wrote:
> Hi all,
>
> If there's a class StringScanner, I run 'ri StringScanner' and read
> the documentation on how to use it, but nowhere it mentions the
> 'require' line needed, how do we usually find it out? I had to google
> to find out that `require 'strscan'` is the line needed...
>
> When I asked about this on IRC, they said run ` egrep -r
> 'StringScanner' /usr/lib/ruby/1.8`, but I was really hoping there's a
> builtin way of doing it.
>
> Thanks,
> Swaroop

I'd vote for having the require line obligatory for stdlib libraries
documentation. I'd also appreciate it, if at least stdlib would follow
the convention for file names. Unless I'm mistaken and having filenames
all lowercase of the class isn't a convention (then I'd vote for coming
up with a convention).
I don't think it's that hard to put a proxy file in for all
unconventional libs requiring the file following the convention to keep
backwards-compatibility (e.g. strscan.rb just containing a line 'require
"stringscanner.rb"').

Regards
Stefan

--
Posted via http://www.ruby-....

Swaroop C H

7/1/2007 3:11:00 PM

0

> You can look at the online documentation
> (http://www.ruby-doc...) and at the standard library
> reference (http://www.ruby-doc.o...). I hope this helps
> Stefano

I now realize that I could have referred my PDF copy of 'Programming
Ruby' to see the documentation (which I'll do in future).

But the idea of looking at the websites is not appealing, what if I
wanted to program offline? :)

Thanks,
Swaroop

--
ion | power your music
Get your own ion right now at www.ion.co.in !

Swaroop C H

7/1/2007 3:14:00 PM

0

On 7/1/07, Stefan Rusterholz <apeiros@gmx.net> wrote:
> I'd vote for having the require line obligatory for stdlib libraries
> documentation. I'd also appreciate it, if at least stdlib would follow
> the convention for file names. Unless I'm mistaken and having filenames
> all lowercase of the class isn't a convention (then I'd vote for coming
> up with a convention).
> I don't think it's that hard to put a proxy file in for all
> unconventional libs requiring the file following the convention to keep
> backwards-compatibility (e.g. strscan.rb just containing a line 'require
> "stringscanner.rb"').

+1 to everything you said here :)

Cheers,
Swaroop
--
ion | power your music
Get your own ion right now at www.ion.co.in !

John Joyce

7/1/2007 3:25:00 PM

0


On Jul 1, 2007, at 10:13 AM, Swaroop C H wrote:

> On 7/1/07, Stefan Rusterholz <apeiros@gmx.net> wrote:
>> I'd vote for having the require line obligatory for stdlib libraries
>> documentation. I'd also appreciate it, if at least stdlib would
>> follow
>> the convention for file names. Unless I'm mistaken and having
>> filenames
>> all lowercase of the class isn't a convention (then I'd vote for
>> coming
>> up with a convention).
>> I don't think it's that hard to put a proxy file in for all
>> unconventional libs requiring the file following the convention to
>> keep
>> backwards-compatibility (e.g. strscan.rb just containing a line
>> 'require
>> "stringscanner.rb"').
>
>
Interesting, considering the fact that those files are the Ruby
standard library, perhaps that is the convention. And I can guess
Matz's reasoning: not all file systems are case sensitive. Also,
considering the source for Ruby is in C and the tradition there is to
use lowercase for .h library files. If all library files are
lowercase, there is never a problem with dependencies being broken by
such a trivial problem. In many programming environments this has
been the very simple source of much trouble.

Tim Hunter

7/1/2007 3:50:00 PM

0

Swaroop C H wrote:
>> You can look at the online documentation
>> (http://www.ruby-doc...) and at the standard library
>> reference (http://www.ruby-doc.o...). I hope this helps
>> Stefano
>
> I now realize that I could have referred my PDF copy of 'Programming
> Ruby' to see the documentation (which I'll do in future).
>
> But the idea of looking at the websites is not appealing, what if I
> wanted to program offline? :)
>
> Thanks,
> Swaroop
>
Use a book?

--
RMagick OS X Installer [http://rubyforge.org/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]


SonOfLilit

7/1/2007 4:07:00 PM

0

On 7/1/07, Tim Hunter <TimHunter@nc.rr.com> wrote:
> Swaroop C H wrote:
> >> You can look at the online documentation
> >> (http://www.ruby-doc...) and at the standard library
> >> reference (http://www.ruby-doc.o...). I hope this helps
> >> Stefano
> >
> > I now realize that I could have referred my PDF copy of 'Programming
> > Ruby' to see the documentation (which I'll do in future).
> >
> > But the idea of looking at the websites is not appealing, what if I
> > wanted to program offline? :)
> >
> > Thanks,
> > Swaroop
> >
> Use a book?
>
> --
> RMagick OS X Installer [http://rubyforge.org/project...]
> RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
> RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]
>
>
>


Build your own version of the rdoc. This is what I did. I also found
on the net a template that made it MUCH prettier and gave me built-in
Javascript-driven search-as-you-type for classes, files and methods,
instead of the ugly frames.

This, I think, is what a ruby programmer is assumed and supposed to do
(I mean, compared to full rdoc html, ri looks like a hack).


Aur

Alex Young

7/1/2007 4:27:00 PM

0

Stefan Rusterholz wrote:
> Swaroop C H wrote:
>> Hi all,
>>
>> If there's a class StringScanner, I run 'ri StringScanner' and read
>> the documentation on how to use it, but nowhere it mentions the
>> 'require' line needed, how do we usually find it out? I had to google
>> to find out that `require 'strscan'` is the line needed...
>>
>> When I asked about this on IRC, they said run ` egrep -r
>> 'StringScanner' /usr/lib/ruby/1.8`, but I was really hoping there's a
>> builtin way of doing it.
>>
>> Thanks,
>> Swaroop
>
> I'd vote for having the require line obligatory for stdlib libraries
> documentation. I'd also appreciate it, if at least stdlib would follow
> the convention for file names. Unless I'm mistaken and having filenames
> all lowercase of the class isn't a convention (then I'd vote for coming
> up with a convention).
> I don't think it's that hard to put a proxy file in for all
> unconventional libs requiring the file following the convention to keep
> backwards-compatibility (e.g. strscan.rb just containing a line 'require
> "stringscanner.rb"').

In general, I agree, and this precise problem has annoyed the hell out
of me in the past. However, you also need to take into account those
libraries that provide more than one class or namespace, or those that
primarily modify core classes. It's not insurmountable, by any means.

--
Alex

Stefan Rusterholz

7/1/2007 4:42:00 PM

0

Alex Young wrote:
> Stefan Rusterholz wrote:
>>> builtin way of doing it.
>> unconventional libs requiring the file following the convention to keep
>> backwards-compatibility (e.g. strscan.rb just containing a line 'require
>> "stringscanner.rb"').
>
> In general, I agree, and this precise problem has annoyed the hell out
> of me in the past. However, you also need to take into account those
> libraries that provide more than one class or namespace, or those that
> primarily modify core classes. It's not insurmountable, by any means.

I keep everything that modifies core classes under a dir called "ruby",
so I do e.g.
require 'ruby/array/sum' (I can also require 'ruby/array', which will
require all sub-files)
I'm still missing a good strategy for singleton methods, though.
Namespaces are mapped to directories in my libs. Stdlib does for a lot
of that the same, consider all the Net::* stuff, it maps to net/*

Regards
Stefan

--
Posted via http://www.ruby-....

Eli Bendersky

7/2/2007 3:00:00 PM

0

On Jul 1, 6:07 pm, SonOfLilit <sonofli...@gmail.com> wrote:
> On 7/1/07, Tim Hunter <TimHun...@nc.rr.com> wrote:
>
>
>
> > Swaroop C H wrote:
> > >> You can look at the online documentation
> > >> (http://www.ruby-doc...) and at the standard library
> > >> reference (http://www.ruby-doc.o...). I hope this helps
> > >> Stefano
>
> > > I now realize that I could have referred my PDF copy of 'Programming
> > > Ruby' to see the documentation (which I'll do in future).
>
> > > But the idea of looking at the websites is not appealing, what if I
> > > wanted to program offline? :)
>
> > > Thanks,
> > > Swaroop
>
> > Use a book?
>
> > --
> > RMagick OS X Installer [http://rubyforge.org/project...]
> > RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
> > RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]
>
> Build your own version of the rdoc. This is what I did. I also found
> on the net a template that made it MUCH prettier and gave me built-in
> Javascript-driven search-as-you-type for classes, files and methods,
> instead of the ugly frames.
>

I would really be interested in seeing your adjustments to RDoc, or a
link to that template with built-in JS search. Sounds like something
very useful !

TIA
Eli