From: 7stud -- Date: 2011-04-17T03:43:05+09:00 Subject: Re: looking for an "inversion" pattern 7stud -- wrote in post #993237: > I guess since obj *is* visible in all the nested blocks, its not strictly necessary to do the singleton = self trick--you can always get the singleton class from obj using obj.singleton_class: class MyClass def self.some_method(obj, *args) puts "MyClass.some_method:" puts "obj: #{obj.inspect}" puts "args: #{args.inspect}" end end def define_foo(obj, clazz, method) obj.singleton_class.class_eval do define_method :foo do obj.singleton_class.singleton_class.class_eval do define_method method do |*args| clazz.send(method, obj, *args) end end obj.singleton_class end end end -- Posted via http://www.ruby-forum.com/.