0

Using Pry show-source it's not showing me the method implementation as I expected:

[2] pry(main)> show-source Object#extend

From: eval.c (C Method):
Owner: Kernel
Visibility: public
Number of lines: 3

static VALUE
rb_obj_extend(argc, argv, obj)
int argc;

That's all I get, but according to the official docs (I have pry-doc installed) I should see:

[1] pry(main)> show-source Object#extend

From: eval.c (C Method):
Owner: Kernel
Visibility: public
Number of lines: 16

static VALUE
rb_obj_extend(int argc, VALUE *argv, VALUE obj)
{
    int i;

    if (argc == 0) {
         rb_raise(rb_eArgError, "wrong number of arguments (at least 1)");
    }
    for (i = 0; i < argc; i++)
    Check_Type(argv[i], T_MODULE);
    while (argc--) {
        rb_funcall(argv[argc], rb_intern("extend_object"), 1, obj);
        rb_funcall(argv[argc], rb_intern("extended"), 1, obj);
    }
    return obj;
}
[2] pry(main)>

Any ideas about why is this happening?

Daniel Romero
  • 1,581
  • 1
  • 20
  • 33
  • It's not a bug, it's expected behaviour. How you expect for Ruby to show C code from compiled binary? – Mike Szyndel May 14 '14 at 18:31
  • From the official documentation: "When the pry-doc plugin is installed (gem install pry-doc) the C source for Ruby core methods (MRI) become available." – Daniel Romero May 15 '14 at 08:00
  • Sorry, I must have misread that. – Mike Szyndel May 15 '14 at 08:19
  • pry-doc holds source code for methods that are written in C, so when you look up one of them you get source from this gem, since it's not possible to decompile it from Ruby. – Mike Szyndel May 15 '14 at 08:20
  • And if you don't understand what I just wrote I think you should make yourself familiar with C programming language a little. – Mike Szyndel May 15 '14 at 08:21
  • I understand that, but my question is given that I'm using the pry-doc gem, why it's not showing the source? as it's suppose to. It's not about decompiling C code to see the implementation. – Daniel Romero May 15 '14 at 09:13
  • From https://github.com/pry/pry-doc "Pry Doc is also smart enough to get any documentation for methods and classes implemented in C." and "Pry Doc supports the following Rubies: ·MRI 2.1" which is what I'm using. – Daniel Romero May 15 '14 at 09:21
  • Also "Pry Doc extends two core Pry commands: show-doc and show-source (aliased as ? and $ respectively).". In my case show-doc it's working properly but not show-source. – Daniel Romero May 15 '14 at 09:28

1 Answers1

0

This solved it for me:

$ rvm docs generate all

Also useful, if you want to generate the ri docs for all your installed gems:

gem rdoc --all --ri --no-rdoc

Daniel Romero
  • 1,581
  • 1
  • 20
  • 33