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

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

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

Alle domenica 1 luglio 2007, Swaroop C H ha scritto:

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

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

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? :slight_smile:

Thanks,
Swaroop

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

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.

On 7/1/07, Stefan R. [email protected] 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 :slight_smile:

Cheers,
Swaroop

On 7/1/07, Tim H. [email protected] wrote:

wanted to program offline? :slight_smile:

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

Swaroop C H wrote:

Thanks,
Swaroop

Use a book?

Alex Y. wrote:

Stefan R. 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

Stefan R. 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs