Clean install OSX 10.9.1 returns “undefined method `path2class'” when trying to install gems

后端 未结 6 1727
时光取名叫无心
时光取名叫无心 2021-02-12 22:15

I just installed a clean Mavericks installation with Homebrew and RVM. Both brew doctor and rvm requirements return \"all good\", however, when I run <

6条回答
  •  情深已故
    2021-02-12 22:28

    Immediate Cause

    psych.so is not located at the proper location.

    Solution/Workaround

    In my case,

    cp /usr/local/share/ruby/gems/2.0/gems/psych-2.0.13/lib/psych.so \
       /usr/share/ruby/vendor_ruby/2.0/
    


    Details

    path2class method is defined in psych_to_ruby.c and registered into Psych::ClassLoader class as a private method by rb_define_private_method(). The following is the code. Take a look at the last line of Init_psych_to_ruby() function.

    static VALUE path2class(VALUE self, VALUE path)
    {
    #ifdef HAVE_RUBY_ENCODING_H
        return rb_path_to_class(path);
    #else
        return rb_path2class(StringValuePtr(path));
    #endif
    }
    
    void Init_psych_to_ruby(void)
    {
        VALUE psych     = rb_define_module("Psych");
        VALUE class_loader  = rb_define_class_under(psych, "ClassLoader", rb_cObject);
    
        VALUE visitors  = rb_define_module_under(psych, "Visitors");
        VALUE visitor   = rb_define_class_under(visitors, "Visitor", rb_cObject);
        cPsychVisitorsToRuby = rb_define_class_under(visitors, "ToRuby", visitor);
    
        rb_define_private_method(cPsychVisitorsToRuby, "build_exception", build_exception, 2);
        rb_define_private_method(class_loader, "path2class", path2class, 1);
    }
    

    Init_psych_to_ruby() is called from Init_psych() function, which is defined in psych.c.

    void Init_psych(void)
    {
        mPsych = rb_define_module("Psych");
    
        rb_define_singleton_method(mPsych, "libyaml_version", libyaml_version, 0);
    
        Init_psych_parser();
        Init_psych_emitter();
        Init_psych_to_ruby();
        Init_psych_yaml_tree();
    }
    

    Ruby calls Init_{library}() function after it loads the library's shared library (.so file). So, in the case of psych, if psych.so is found and loaded, Init_psych() function is called and in turn Init_psych_to_ruby() is called, and finally path2class is registered. However, if psych.so does not exist, path2class is never registered and you will see the error message "undefined method `path2class'".

    Probably, there is something wrong in the packaging process of either psych or Ruby.

提交回复
热议问题