Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.6, 1.6-beta-1
-
Fix Version/s: 1.7-beta-1
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
It is not possible to provide an instance-level methodMissing() implementation for a class via ExpandoMetaClass. Note that it is possible to do this for the static version of the method. See the attached test case.
Hi,
I am attaching patches for branches 1.5.x and 1.6.x that resolved this issue and an accompanying test case.
There was no issue with specifying methodMissing at instance level. Issue was related to how a method is identified internally as the special MethodMissing method.
A method gets registered as the special missingMethod only if its name is "methodMissing" and it takes 2 parameters - 1st String and 2nd Object.
In the following code, although the name is methodMissing, the types of parameters are [Object, Object] and hence it does not get registered as methodMissing at EMC level:
TestClass.metaClass.methodMissing = { method, args -> return method }So, one work around is to use the syntax:
TestClass.metaClass.methodMissing = { String method, args -> return method }Now "new TestClass().test()" correctly invokes missingMethod().
However, with the patch supplied, even if method name's type is not explicitly specified as String, it still gets handled and methodMissing works as expected.
rgds,
Roshan