From: Joel VanderWerf Date: 2002-08-05T07:56:31+09:00 Subject: Re: Can I get a method object for a class method? Ned Konz wrote: > On Sunday 04 August 2002 03:18 pm, Jim Freeze wrote: > > >>Is is possible to get a pointer to a class method as in the >>code below: > > > > class A > def self.xyz > p "I'm xyz" > end > @@classMeth = method(:xyz) > def initialize > @f1 = @@classMeth > end > def test > @f1.call > end > end > > A.new.test > If you subclass A, this will bite you: class B < A def self.xyz p "I'm xyz in B" end end B.new.test # ==> "I'm xyz" Instead: class A def initialize @f1 = self.class.method(:xyz) # or use 'type' for 'self.class' end end B.new.test # ==> "I'm xyz in B"