From: Trans Date: 2007-06-27T02:12:58+09:00 Subject: Re: Class instance into included module On Jun 26, 1:00 pm, Galevsky Gal wrote: > Hi all, > > here is my problem: I would like to handle class instances into a module > included by the class. This case is illustrated below: > > module Mod > instanceOfClas = ??? > method_HelloWorld = instanceOfClas.method('helloWorld') > > # do something with the method that could be: > method_HelloWorld.call if iwant > end > > class Clas > include Mod > > def helloWorld > "Hello world !" > end > end > > Do you have any idea ? I cannot get my instance using self since self > means the module itself. How can I make a .call onto *parent* class > method ? The way you have it paradoxical b/c "method_HelloWorld.call if iwant" is happening before an instance is ever created. BUt if you just men accessing Clas, then just put that: method_HelloWorld = Clas.instance_method('helloWorld') However, Ruby has some limitations, in that a method needs to be bound to an instance. And binding is restricted to subclasses of the type of class the method was taken from. Unfortunate that. But usually one can find a way to manage. In your case you should ask "what am I trying to call an instance method outside of an instance? Maybe it should be a module method, which the instance can call upon instead. T.