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

S

Swaroop C H

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
 
S

Stefano Crocco

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.org/core/) and
at the standard library reference (http://www.ruby-doc.org/stdlib/).

I hope this helps

Stefano
 
S

Stefan Rusterholz

Swaroop said:
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
 
S

Swaroop C H

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
 
J

John Joyce

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.
 
T

Tim Hunter

Swaroop said:
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?
 
S

SonOfLilit

Use a book?


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
 
A

Alex Young

Stefan said:
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.
 
S

Stefan Rusterholz

Alex said:
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
 
E

Eli Bendersky

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top