module Kernel
def methodClass(m)
m = m.to_s
# catch method undef’s
respond_to?(m) or return nil
# meta class is first inline
extended_anc = self.class.ancestors.unshift(class << self; self end)
extended_anc.find {|c| c.instance_methods.include?(m) }
end
end
module Kernel
def methodClass(m)
m = m.to_s
# catch method undef’s
respond_to?(m) or return nil
# meta class is first inline
extended_anc = self.class.ancestors.unshift(class << self; self end)
extended_anc.find {|c| c.instance_methods.include?(m) }
end
end
Hm. Since #respond_to? is doing this work alread, maybe it would make
sense for it to return the Module where it finds a method, instead of
just true?
Sorta like how defined?(arg) returns not just a boolean value but the
kind of thing arg is.
module Kernel
def methodClass(m)
m = m.to_s
# catch method undef’s
respond_to?(m) or return nil
# meta class is first inline
extended_anc = self.class.ancestors.unshift(class << self; self end)
extended_anc.find {|c| c.instance_methods.include?(m) }
end
end
Hm. Since #respond_to? is doing this work alread, maybe it would make
sense for it to return the Module where it finds a method, instead of
just true?
Maybe nice.
Sorta like how defined?(arg) returns not just a boolean value but the
kind of thing arg is.
defined?(arg) returns a string represents type of arg or nil,
not true/false.
···
At Thu, 19 Dec 2002 07:41:14 +0900, Joel VanderWerf wrote:
if Ruby will call some method before adding each method, it will be possible
Unfortunately, such hooks are only Class#method_added and so
on, which will be called after it.
class Class
def method_added
puts “sorry, it’s too late to save prevous method definition”
puts “… but i can save the current definition for future references”
puts “… are you sure you are absolutely need to do IT?”
if gets==“y”
$secret_hash[class][method] << method_definition
end
end
end