netbeans 如何查看ruby源代码?

请问一下,如何才能在netbeans利用ctrl+鼠标左键,查看ruby源码,比如:

ss = Array.new

然后我想查看具体ruby内置的array是如何实现的,要怎么查看啊?或者说要在netbeans如何设置?,我目前看不到源码,只能看到注释。


希望大家知道的告诉一下,谢谢~~~~

由于Array是比较核心的类,为了速度考虑,源代码是用C写的,netbeans是看不到C的源代码的(已经编译了)。

你可以看Ruby doc
[url]http://www.ruby-doc.org/core/[/url]

RDoc的方法,[b]点击方法名字[/b]就能看到包含源代码的弹出窗口。

下面这段是Array.new的实现。
在C中,ruby的值类型是VALUE,VALUE是一个无符号整数,可以认为它是对象的ID。
btw,符号ID由rb_intern(VALUE v)得到。
[code="c"]
/*

  • call-seq:
  • Array.new(size=0, obj=nil)
  • Array.new(array)
  • Array.new(size) {|index| block } *
  • Returns a new array. In the first form, the new array is
  • empty. In the second it is created with size copies of obj
  • (that is, size references to the same
  • obj). The third form creates a copy of the array
  • passed as a parameter (the array is generated by calling
  • to_ary on the parameter). In the last form, an array
  • of the given size is created. Each element in this array is
  • calculated by passing the element's index to the given block and
  • storing the return value. *
  • Array.new
  • Array.new(2)
  • Array.new(5, "A")
  • # only one copy of the object is created
  • a = Array.new(2, Hash.new)
  • a[0]['cat'] = 'feline'
  • a
  • a[1]['cat'] = 'Felix'
  • a
  • # here multiple copies are created
  • a = Array.new(2) { Hash.new }
  • a[0]['cat'] = 'feline'
  • a
  • squares = Array.new(5) {|i| i*i}
  • squares
  • copy = Array.new(squares) */

static VALUE
rb_ary_initialize(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
{
long len;
VALUE size, val;

rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
    RARRAY(ary)->len = 0;
    if (rb_block_given_p()) {
        rb_warning("given block not used");
    }
    return ary;
}

if (argc == 1 && !FIXNUM_P(size)) {
    val = rb_check_array_type(size);
    if (!NIL_P(val)) {
        rb_ary_replace(ary, val);
        return ary;
    }
}

len = NUM2LONG(size);
if (len < 0) {
    rb_raise(rb_eArgError, "negative array size");
}
if (len > 0 && len * (long)sizeof(VALUE) <= len) {
    rb_raise(rb_eArgError, "array size too big");
}
if (len > RARRAY(ary)->aux.capa) {
    REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
    RARRAY(ary)->aux.capa = len;
}
if (rb_block_given_p()) {
    long i;

    if (argc == 2) {
        rb_warn("block supersedes default value argument");
    }
    for (i=0; i<len; i++) {
        rb_ary_store(ary, i, rb_yield(LONG2NUM(i)));
        RARRAY(ary)->len = i + 1;
    }
}
else {
    memfill(RARRAY(ary)->ptr, len, val);
    RARRAY(ary)->len = len;
}

return ary;

}
[/code]

查看ruby实现的源代码,一种方法是[b]navigate[/b](查看工程中所有对象列表),另一种方法是[b]CTRL+B[/b]跳到声明处。

常用的几个快捷键

在controller和view直接跳转 - Ctrl + Shift + A

在controller/model和test/spec之间跳转 - Ctrl + Shift + T

[color=red]直接跳转到类和方法的源代码 - Ctrl + B[/color]

自动补齐 - Ctrl + \

方法参数提示 - Ctrl + P

快速修复提示 - Alt + Enter
上下文帮助 - Ctrl + Shift + Enter
重命名重构 - Ctrl + R

还有一个用鼠标操作的,挺好用的:
按住Ctrl,移动光标到指定位置,会有相关提示。单击鼠标就会跳转到类和方法的源代码,相当于Ctrl + B

看错了,不好意思~~