[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

about method docs

Santanu

12/27/2007 1:33:00 PM

Hello Everybody,

I started learning ruby recently (yesterday). I am using the
interactive irb to try out the various ruby features. But I am
very much missing the help feature which I was so used to
in the python's interactive environment, the __doc__ feature,
etc. (I hope at least some of you have used Python before
and know what I mean).

I am sure there must be something similar accessible from
within irb, but I don't know where to look. It would be very
helpful if you could please point me to the right direction.

Thnanks in advance for your help.

Regards,
Santanu Chatterjee
15 Answers

Jeremy McAnally

12/27/2007 1:57:00 PM

0

I believe you can use `help`. For example: help puts

--Jeremy

On Dec 27, 2007 8:35 AM, Santanu <thisissantanu@gmail.com> wrote:
> Hello Everybody,
>
> I started learning ruby recently (yesterday). I am using the
> interactive irb to try out the various ruby features. But I am
> very much missing the help feature which I was so used to
> in the python's interactive environment, the __doc__ feature,
> etc. (I hope at least some of you have used Python before
> and know what I mean).
>
> I am sure there must be something similar accessible from
> within irb, but I don't know where to look. It would be very
> helpful if you could please point me to the right direction.
>
> Thnanks in advance for your help.
>
> Regards,
> Santanu Chatterjee
>
>



--
http://www.jeremymca...

My books:
Ruby in Practice
http://www.manning.com...

My free Ruby e-book
http://www.humblelittlerub...

My blogs:
http://www.mrneigh...
http://www.rubyinpra...

Santanu

12/27/2007 2:23:00 PM

0

On Dec 27, 6:56 pm, Jeremy McAnally <jeremymcana...@gmail.com> wrote:
> I believe you can use `help`. For example: help puts
>

First of all, thanks for your response.
Yes, I did try things like 'help puts', but all I get are these error
messages:
-------------------------------------------
irb(main):032:0> help puts

No ri documentation found in:

Was rdoc run to create documentation?

Errno::ENOENT: No such file or directory - (null)
from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `initialize'
from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `open'
from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `usage_no_exit'
from /usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'
from /usr/lib/ruby/1.8/rdoc/ri/ri_driver.rb:39:in
`report_missing_documentation'
from /usr/lib/ruby/1.8/rdoc/ri/ri_driver.rb:25:in `initialize'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
from (eval):3:in `help'
from (irb):32
from (null):0
irb(main):033:0>
-------------------------------------

I use Ubuntu 7.10, and I have already installed rdoc. I don't
understand
the error message much but it seems I have to do something else to
make the help command work. Do I have to install ruby source and run
rdoc through them?

Regards,
Santanu

Jeremy McAnally

12/27/2007 2:41:00 PM

0

Oops. The `puts` keyword is a bad example. :)

>> help puts

Errno::ENOENT: No such file or directory - /cdesc-::.yaml
from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `initialize'
from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `open'
from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `get_class'
from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:52:in `each'
---------------------------------------------------------- Class: String
A +String+ object holds and manipulates an arbitrary sequence of
bytes, typically representing characters. String objects may be
created using +String::new+ or as literals.

Because of aliasing issues, users of strings should be aware of the
methods that modify the contents of a +String+ object. Typically,
methods with names ending in ``!'' modify their receiver, while
those without a ``!'' return a new +String+. However, there are
exceptions, such as +String#[]=+.

------------------------------------------------------------------------
Enhance the String class with a XML escaped character version of
to_s.

------------------------------------------------------------------------
Enhance the String class with a XML escaped character version of
to_s.

------------------------------------------------------------------------
Enhance the String class with a XML escaped character version of
to_s.


I don't know why that error is there...but oh well.

--Jeremy

On Dec 27, 2007 9:24 AM, Santanu <thisissantanu@gmail.com> wrote:
> On Dec 27, 6:56 pm, Jeremy McAnally <jeremymcana...@gmail.com> wrote:
> > I believe you can use `help`. For example: help puts
> >
>
> First of all, thanks for your response.
> Yes, I did try things like 'help puts', but all I get are these error
> messages:
> -------------------------------------------
> irb(main):032:0> help puts
>
> No ri documentation found in:
>
> Was rdoc run to create documentation?
>
> Errno::ENOENT: No such file or directory - (null)
> from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `initialize'
> from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `open'
> from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `usage_no_exit'
> from /usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'
> from /usr/lib/ruby/1.8/rdoc/ri/ri_driver.rb:39:in
> `report_missing_documentation'
> from /usr/lib/ruby/1.8/rdoc/ri/ri_driver.rb:25:in `initialize'
> from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
> `gem_original_require'
> from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
> from (eval):3:in `help'
> from (irb):32
> from (null):0
> irb(main):033:0>
> -------------------------------------
>
> I use Ubuntu 7.10, and I have already installed rdoc. I don't
> understand
> the error message much but it seems I have to do something else to
> make the help command work. Do I have to install ruby source and run
> rdoc through them?
>
> Regards,
> Santanu
>
>



--
http://www.jeremymca...

My books:
Ruby in Practice
http://www.manning.com...

My free Ruby e-book
http://www.humblelittlerub...

My blogs:
http://www.mrneigh...
http://www.rubyinpra...

MonkeeSage

12/27/2007 3:06:00 PM

0

On Dec 27, 8:22 am, Santanu <thisissant...@gmail.com> wrote:
> On Dec 27, 6:56 pm, Jeremy McAnally <jeremymcana...@gmail.com> wrote:
>
> > I believe you can use `help`. For example: help puts
>
> First of all, thanks for your response.
> Yes, I did try things like 'help puts', but all I get are these error
> messages:
> -------------------------------------------
> irb(main):032:0> help puts
>
> No ri documentation found in:
>
> Was rdoc run to create documentation?
>
> Errno::ENOENT: No such file or directory - (null)
> from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `initialize'
> from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `open'
> from /usr/lib/ruby/1.8/rdoc/usage.rb:100:in `usage_no_exit'
> from /usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'
> from /usr/lib/ruby/1.8/rdoc/ri/ri_driver.rb:39:in
> `report_missing_documentation'
> from /usr/lib/ruby/1.8/rdoc/ri/ri_driver.rb:25:in `initialize'
> from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
> `gem_original_require'
> from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
> from (eval):3:in `help'
> from (irb):32
> from (null):0
> irb(main):033:0>
> -------------------------------------
>
> I use Ubuntu 7.10, and I have already installed rdoc. I don't
> understand
> the error message much but it seems I have to do something else to
> make the help command work. Do I have to install ruby source and run
> rdoc through them?
>
> Regards,
> Santanu

Maybe there are ri / ruby-doc / ruby-dev packages that provide the
docs? You shouldn't have to build from source...I can't imagine the
maintainers of Ubuntu would leave it out altogether. But I could be
wrong...in which case here is a guide for building ruby from source on
ubuntu (it's easy :) http://www.rubywizards.com/viewtopic....

Regards,
Jordan

George

12/27/2007 3:59:00 PM

0

On Dec 28, 2007 1:40 AM, Jeremy McAnally <jeremymcanally@gmail.com> wrote:
> Oops. The `puts` keyword is a bad example. :)
>
> >> help puts
>
> Errno::ENOENT: No such file or directory - /cdesc-::.yaml
> from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `initialize'
> from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `open'
> from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:54:in `get_class'
> from /opt/local/lib/ruby/1.8/rdoc/ri/ri_reader.rb:52:in `each'

Hi Jeremy,

There are no keywords here; #help is just a method that expects a
string, and #puts is returning nil. Try:

>> help 'puts'

Alternatively, just:

$ ri puts

on the command line.

Regards,
George.

Santanu

12/27/2007 4:24:00 PM

0

On Dec 27, 8:05 pm, MonkeeSage <MonkeeS...@gmail.com> wrote:
> On Dec 27, 8:22 am, Santanu <thisissant...@gmail.com> wrote:
> > On Dec 27, 6:56 pm, Jeremy McAnally <jeremymcana...@gmail.com> wrote:
>
> > > I believe you can use `help`. For example: help puts
> > Yes, I did try things like 'help puts', but all I get are these error
> > messages:
> > -------------------------------------------
> > irb(main):032:0> help puts
>
> > No ri documentation found in:
>
> > Was rdoc run to create documentation?
> > .........
> > -------------------------------------
>
> > I use Ubuntu 7.10, and I have already installed rdoc. I don't
> > understand
> > the error message much but it seems I have to do something else to
> > make the help command work. Do I have to install ruby source and run
> > rdoc through them?

> Maybe there are ri / ruby-doc / ruby-dev packages that provide the
> docs? You shouldn't have to build from source...I can't imagine the
> maintainers of Ubuntu would leave it out altogether. But I could be
> wrong...in which case here is a guide for building ruby from source on
> ubuntu (it's easy :)http://www.rubywizards.com/viewtopic....

Thanks. Just now I compiled ruby-1.9 and installed it with docs. Now,
at least
help command at the irb prompt provides some help. 'help puts' is
still
problematic though, but things like 'help Array' does give some
understandable
result.

However, I am still searching for the exact syntax for asking for help
on say, Array.collect, etc. at the irb prompt. Any pointers?

Regards,
Santanu

Stephen Duncan Jr

12/27/2007 4:36:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Dec 27, 2007 11:24 AM, Santanu <thisissantanu@gmail.com> wrote:

> Thanks. Just now I compiled ruby-1.9 and installed it with docs. Now,
> at least
> help command at the irb prompt provides some help. 'help puts' is
> still
> problematic though, but things like 'help Array' does give some
> understandable
> result.
>
> However, I am still searching for the exact syntax for asking for help
> on say, Array.collect, etc. at the irb prompt. Any pointers?
>
> Regards,
> Santanu
>
>
>> help 'Array#collect'

-Stephen


--
Stephen Duncan Jr
www.stephenduncanjr.com

Santanu

12/27/2007 4:41:00 PM

0

On Dec 27, 8:58 pm, George <george.og...@gmail.com> wrote:

> #help is just a method that expects a
> string, and #puts is returning nil. Try:
>
> >> help 'puts'

Thanks. That solved my last problem with irb. After I compiled
and installed ruby from source. I was wondering why I could
not do things like 'help Array.collect'. Now I think I get it.
Yeah... help 'Array.collect' works now.

Thanks again.

Regards,
Santanu

Santanu

12/27/2007 4:49:00 PM

0

On Dec 27, 9:35 pm, Stephen Duncan <stephen.dun...@gmail.com> wrote:
> On Dec 27, 2007 11:24 AM, Santanu <thisissant...@gmail.com> wrote:
> > However, I am still searching for the exact syntax for asking for help
> > on say, Array.collect, etc. at the irb prompt. Any pointers?

> >> help 'Array#collect'

Thanks. That works. By the way, "help 'Array.collect'" works too.
Are Array.collect and Array#collect equivalent or is this about
class method vs. instance method. (I don't know ruby that much
yet. Just started learning it from "Ruby By Example" yesterday).

Regards,
Santanu

MonkeeSage

12/27/2007 5:11:00 PM

0

On Dec 27, 10:23 am, Santanu <thisissant...@gmail.com> wrote:
> On Dec 27, 8:05 pm, MonkeeSage <MonkeeS...@gmail.com> wrote:
>
>
>
> > On Dec 27, 8:22 am, Santanu <thisissant...@gmail.com> wrote:
> > > On Dec 27, 6:56 pm, Jeremy McAnally <jeremymcana...@gmail.com> wrote:
>
> > > > I believe you can use `help`. For example: help puts
> > > Yes, I did try things like 'help puts', but all I get are these error
> > > messages:
> > > -------------------------------------------
> > > irb(main):032:0> help puts
>
> > > No ri documentation found in:
>
> > > Was rdoc run to create documentation?
> > > .........
> > > -------------------------------------
>
> > > I use Ubuntu 7.10, and I have already installed rdoc. I don't
> > > understand
> > > the error message much but it seems I have to do something else to
> > > make the help command work. Do I have to install ruby source and run
> > > rdoc through them?
> > Maybe there are ri / ruby-doc / ruby-dev packages that provide the
> > docs? You shouldn't have to build from source...I can't imagine the
> > maintainers of Ubuntu would leave it out altogether. But I could be
> > wrong...in which case here is a guide for building ruby from source on
> > ubuntu (it's easy :)http://www.rubywizards.com/viewtopic....
>
> Thanks. Just now I compiled ruby-1.9 and installed it with docs. Now,
> at least
> help command at the irb prompt provides some help. 'help puts' is
> still
> problematic though, but things like 'help Array' does give some
> understandable
> result.
>
> However, I am still searching for the exact syntax for asking for help
> on say, Array.collect, etc. at the irb prompt. Any pointers?
>
> Regards,
> Santanu

Sure, be glad to. :)


# help about the instance method "reverse_each"
# (found in class Array).
help "send"


# if multiple methods match, it will give a list with
# the qualifying namespaces. note that symbols can be
# used rather than strings as the argument to #help
help :index


# instance method "each_slice" of Enumerable module.
# note the string use, so that ruby doesn't try to
# call each_slice on a Symbol object (:Enumerable)
# note also that the "#" could be spelled as "."
# and ri doesn't care; but "#" is the usual spelling
# you'll see round here when speaking about methods
help "Enumerable#each_slice"


# help about an instance method of a module nested
# in a class. note the string again. like in ruby
# itself, access to a class/module-level constant
# (in this case a module) is done with "::". but
# for instance-level, we use "#" / "." (only the
"." is valid in actual ruby code)
help "OptionParser::Completion#complete"


# help about a class method of a class nested
# in a class. note again the syntax difference,
# "#" / "." vs. "::".
help "OptionParser::Switch::guess"

Ps. The examples I used aren't the most enlightening, I just opened a
random stdlib file and looked at the first instances of what I was
trying to exemplify; so don't think that all (or even most) of the
ruby documentation is as cryptic or unhelpful as, for example, the
output from ` help "OptionParser::Switch::guess"` heh! ;)

Regards,
Jordan