Forum: Ruby to get help from inside irb console

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sijo k. (Guest)
on 2008-12-11 08:48
Hi
   How to get help from inside irb console I would like to know what the
following is

OpenSSL::Random.random_bytes

Thanks in advance
Sijo
Brian C. (Guest)
on 2008-12-11 11:17
Sijo Kg wrote:
> Hi
>    How to get help from inside irb console I would like to know what the
> following is
>
> OpenSSL::Random.random_bytes
>
> Thanks in advance
> Sijo

Unfortunately the OpenSSL Ruby extensions are not well documented,
especially the C native parts. ri seems to know nothing about them. I
usually dive into the C source, and/or guess based on the OpenSSL C API.

You'll get some documentation here:
http://www.ruby-doc.org/stdlib/

If you click on the 'openssl' link on the left, and then on 'random_key'
in the top right, then on the 'source' link for random_key, you'll get
an example which shows random_bytes in action:

      def random_key
        str = OpenSSL::Random.random_bytes(self.key_len)
        self.key = str
        return str
      end

But if you want to know exactly what random_bytes does, you'll need to
look at OpenSSL's own documentation. man -k may help you search for it.
In this case, "man RAND_bytes" looks like the one.

See also "man 3ssl ssl" or "man 3 ssl", also at
http://www.openssl.org/docs/ssl/ssl.html

As for getting ri help from within irb, you could always do

  system "ri String"

or write something in .irbrc which does this. Google for "irbrc" or "ri
in irbrc" for some ideas.

Often all I do is something like this:

    str = "abc"
    str.methods - Object.instance_methods - Enumerable.instance_methods
Sijo k. (Guest)
on 2008-12-11 12:45
Thanks for your reply..I saw this also
irb_help
For that what I did is
require 'openssl'
irb_help OpenSSL::Random.random_bytes

But this gives me error  ArgumentError: wrong number of arguments (0 for
1)
But when I did like
irb_help OpenSSL::Random.random_bytes(2)
it gives
Nothing known about ��

    What is this irb_help actually?

Sijo
Brian C. (Guest)
on 2008-12-11 13:14
Sijo Kg wrote:
> For that what I did is
> require 'openssl'
> irb_help OpenSSL::Random.random_bytes

Interesting, irb_help is new to me.

> But this gives me error  ArgumentError: wrong number of arguments (0 for
> 1)

That is because what you're really doing there is

  irb_help(OpenSSL::Random.random_bytes())

That is, you're calling the function OpenSSL::Random.random_bytes, which
requires an argument that you're not providing. That's where the error
is raised.

So you need to quote the text:

  irb_help "OpenSSL::Random.random_bytes"

However as I said already, there's no help for this built into
ruby/ri/rdoc.

irb(main):013:0> irb_help "OpenSSL::Random"
Nothing known about OpenSSL::Random

If you're passing a class, you don't need to quote it, because the class
object itself is passed and irb_help converts it to the classname:

irb(main):014:0> irb_help String
... shows info about String
This topic is locked and can not be replied to.