From: Robert Klemme Date: 2006-11-19T06:10:12+09:00 Subject: Re: How to call a class method via the singleton if it exists --------------000806060603090007050503 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 18.11.2006 18:16, Robert Klemme wrote: >> thanks robert. you helped clarify that unfortunately I've i mis-stated >> the problem, there's a contradiction in my example, what I actually >> meant was: >> >> class X >> def self.f ; "A" ; end >> def g ; self.class.f ; end >> end >> >> x = X.new >> x.g #=> "A" >> >> # this should be: >> class << x >> def self.f; "B"; end >> end >> >> x.g #=> "A" # want "B" >> >> so #respond_to? won't help b/c I didn't intend #f to be instance level >> method. sorry. what i'm asking for, should make a whole lot more sense >> now (i hope) >> >> thanks, >> T. > > > Just replace self.class with class< > robert > How about this? robert --------------000806060603090007050503 Content-Type: text/plain; name="dispatch3.rb" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="dispatch3.rb" #!/usr/bin/ruby class Object # option 1 def dispatch(m,*a,&b) [class < "A" p x.h #=> "A" p x.i #=> "A" class << x def self.f; "B"; end end p x.g #=> "A" p x.h #=> "B" p x.i #=> "B" --------------000806060603090007050503--