[#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:6504] Re: redefining methods in a hierarchy.

From: gotoken@... (GOTO Kentaro)
Date: 2000-11-21 19:02:20 UTC
List: ruby-talk #6504
In message "[ruby-talk:6503] redefining methods in a hierarchy."
    on 00/11/22, Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
>If I have an object which I know to be a subclass of a subclass (at lease)
>and I want to override a method, I can do it in that object's class and
>all is well.  But if I can override the method higher up I get more power
>from my change.  My change may not just affect Fixnums, but it might be
>able to work on all numbers, for example.  Given the reflection abilities
>of Ruby, can I ask an object which class really handles a given method?
>Then I know where to make the change.

Are you looking for something like this?

  class Class
    def whereis(meth)
      meth = meth.id2name if meth.is_a? Symbol
      unless meth.is_a? String
	raise TypeError,
	  "wrong argument type #{meth.type} (expected String or Symbol)"
      end

      ancestors.find do |klass|
	klass.instance_methods.include? meth
      end
    end
  end

  p Fixnum.whereis :nonzero?  #=> Numeric
  p Fixnum.whereis :integer?  #=> Integer
  p Fixnum.whereis :zero?     #=> Fixnum
  p Array.whereis :find       #=> Enumerable

-- gotoken

In This Thread