BatistaGoddy 2009-03-18 08:39
浏览 276
已采纳

netbeans 如何查看ruby源代码?

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

ss = Array.new

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


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

  • 写回答

3条回答 默认 最新

  • xenocide 2009-03-18 09:17
    关注

    由于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]跳到声明处。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题