To get help from inside irb console


#1

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


#2

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

#3

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


#4

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