On Feb 15, 2007, at 07:50, Daniel Berger wrote:
> On Feb 14, 1:44 pm, Eric Hodel <drbr... / segment7.net> wrote:
>> On Feb 14, 2007, at 12:05, Daniel Berger wrote:
>>> I think he just means that there's no direct equivalent in plain  
>>> Ruby
>>> (right?).
>>
>> Yup.  I've reimplemented rb_path2class() numerous times in ruby, and
>> there's a perfectly good C method lying around that needs only a one-
>> line patch to be accessible.
>
> I tried messing with object.c yesterday, but I couldn't make it work.
> Any ideas for a patch?  It would be nice to get one in for 1.8.6 if
> possible.

Oh, I was mistaken, its VALUE rb_path2class(const char *) not VALUE  
rb_path2class(VALUE), so a wrapper function needs to be written (so  
more than one line).  I don't know if Object::path2class is a good  
name, since the C implementation can only have Object as its root.

I got this far:

Index: intern.h
===================================================================
--- intern.h    (revision 11758)
+++ intern.h    (working copy)
@@ -453,6 +453,7 @@ VALUE rb_mod_name _((VALUE));
VALUE rb_class_path _((VALUE));
void rb_set_class_path _((VALUE, VALUE, const char*));
VALUE rb_path2class _((const char*));
+VALUE rb_obj_path2class _((VALUE));
void rb_name_class _((VALUE, ID));
VALUE rb_class_name _((VALUE));
void rb_autoload _((VALUE, ID, const char*));
Index: variable.c
===================================================================
--- variable.c  (revision 11758)
+++ variable.c  (working copy)
@@ -274,6 +274,13 @@ rb_path2class(path)
      return c;
}
+VALUE
+rb_obj_path2class(path)
+    VALUE path;
+{
+    return rb_path2class(StringValueCStr(path));
+}
+
void
rb_name_class(klass, id)
      VALUE klass;
Index: object.c
===================================================================
--- object.c    (revision 11758)
+++ object.c    (working copy)
@@ -2646,7 +2646,7 @@ Init_Object()
      rb_define_private_method(rb_cModule, "method_added",  
rb_obj_dummy, 1);
      rb_define_private_method(rb_cModule, "method_removed",  
rb_obj_dummy, 1);
      rb_define_private_method(rb_cModule, "method_undefined",  
rb_obj_dummy, 1);
-
+    rb_define_singleton_method(rb_cObject, "path2class",  
rb_obj_path2class, 1);
      rb_define_method(rb_mKernel, "nil?", rb_false, 0);
      rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);


$ ./ruby186 -e 'p Object.path2class("Struct")'
-e:1:in `path2class': can't convert Class into String (TypeError)
         from -e:1