[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6508] Re: redefining methods in a hierarchy.

From: Yasushi Shoji <yashi@...>
Date: 2000-11-21 20:53:16 UTC
List: ruby-talk #6508
At Wed, 22 Nov 2000 04:02:20 +0900,
GOTO Kentaro wrote:

>   class Class
>     def whereis(meth)
[...]
>     end
>   end
> 
>   p Fixnum.whereis :nonzero?  #=> Numeric
>   p Fixnum.whereis :integer?  #=> Integer
>   p Fixnum.whereis :zero?     #=> Fixnum
>   p Array.whereis :find       #=> Enumerable

p Array.whereis :dup            #=> Kernel

is this ok?  I mean, should the module 'Kernel' exposed to end user?

anyway, I tried to implement in C level.  The patch still have one
problem.  When method is defined at the module 'Kernel', it prints as
follows:

$ ./ruby -e "p Integer.new.method(:dup).defined_at"
#<Kernel:0x401b7c94>
$ ./ruby -e "p Integer.new.method(:dup).defined_at.type"
Kernel

I'd very much appreciate if someone enlighten me.



for others, it seems working ok:

$ ./ruby -e "o Module.defined_at(:class_eval)"
Module
$ ./ruby -e "p Integer.new.method(:+@).defined_at"
Numeric

oh well..
--
         yashi

Index: eval.c
===================================================================
RCS file: /opt/cvsroot/ruby/eval.c,v
retrieving revision 1.124
diff -u -r1.124 eval.c
--- eval.c	2000/11/08 05:29:21	1.124
+++ eval.c	2000/11/21 20:49:42
@@ -6461,6 +6461,36 @@
 }
 
 static VALUE
+method_defined_at(method)
+    VALUE method;
+{
+    struct METHOD *data;
+
+    Data_Get_Struct(method, struct METHOD, data);
+    return data->klass;
+}
+
+static VALUE
+rb_obj_defined_at(self, arg)
+    VALUE self, arg;
+{
+    ID id;
+    NODE *body;
+    VALUE klass, orig;
+
+    id = rb_to_id(arg);
+    klass = rb_class_of(self);
+    orig = klass;
+
+    while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
+	klass = RCLASS(klass)->super;
+	if (!klass)
+	    print_undef(orig, id);
+    }
+    return klass;
+}
+
+static VALUE
 mproc()
 {
     VALUE proc;
@@ -6538,7 +6568,9 @@
     rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
     rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
     rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
+    rb_define_method(rb_cMethod, "defined_at", method_defined_at, 0);
     rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
+    rb_define_method(rb_mKernel, "defined_at", rb_obj_defined_at, 1);
 
     rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cMethod);
     rb_define_method(rb_cUnboundMethod, "call", umethod_call, -1);

In This Thread