Trans wrote:
method_HelloWorld.call if iwant
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.
Thanks for your posts guys ;o)
Well, I am writting a light unit test framework, like Junit for java.
So, I have a TestModule module that deals with Tests objects, assertions
and so on. The behaviour I want is:
Take a class:
Class AClass
def method1
"hello"
end
end
To unit-test it, I would like to just need to write that:
Class TestAClass
def TestMethod1
assume(AClass.new.method,"hello")
end
include TestModule
end
To do that, my TestModule should be....
module TestModule
class TestManager
# handle a tests register, launches all the methods, handles the
results, display info and so on
def register(method)
@register << method
end
def launch
@register.each{ |test|
test.call
}
end
def testsSucceed?
# handle lots stuff with assume() calls executed during the launch
...
end
end
# find all the methods of TestAClass that have 'Test' in their name,
and add them into the register handled by the TestManager
mgr = TestManager.new
testing_instance = #here is my pb and I 'd like to get a TestAClass
instance
testing_instance.methods.each{ |method|
if !(method =~ /Test/).nil?
mgr.register(testing_instance.method(method))
end
}
puts "launch All the registered tests"
mgr.launch
end
I give you a shortened version but the necessary part to understand what
I would like to do.
Thanks for your attention,
Gal'
···
On Jun 26, 1:00 pm, Galevsky Gal <galev...@gmail.com> wrote:
--
Posted via http://www.ruby-forum.com/\.