Skip to content

Instantly share code, notes, and snippets.

@roryl
Last active May 3, 2016 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roryl/1209cf05ae342beeecda87dd879b0150 to your computer and use it in GitHub Desktop.
Save roryl/1209cf05ae342beeecda87dd879b0150 to your computer and use it in GitHub Desktop.
Lucee onMissingMethod Examples
component {
this.triggerDataMember=true;
}
component {
public function onMissingMethod(missingMethodName, missingMethodArguments){
return arguments;
}
}
component {
public function onMissingMethod(missingMethodName, missingMethodArguments){
return this;
}
}
component {
public boolean function add(numeric arg1, numeric arg2){
return arg1 + arg2;
}
public boolean function multiply(numeric arg1, numeric arg2){
return arg1 * arg2;
}
public boolean function subtract(numeric arg1, numeric arg2){
return arg1 - arg2;
}
}
component {
public function onMissingMethod(missingMethodName, missingMethodArguments){
echo("You are trying to #missingMethodName# #missingMethodArguments[1]# and #missingMethodArguments[2]# <br />");
var math = new math();
var result = evaluate("math.#missingMethodName#(argumentCollection=missingMethodArguments)");
echo("The result was #result#");
}
}
component {
public boolean function add(numeric arg1, numeric arg2){
echo("You are trying to add #arg1# and #arg2# <br />");
var math = new math();
var result = math.add(arg1, arg2);
echo("The result was #result# <br />");
return arg1 + arg2;
}
public boolean function multiply(numeric arg1, numeric arg2){
echo("You are trying to multiply #arg1# and #arg2# <br />");
var math = new math();
var result = math.add(arg1, arg2);
echo("The result was #result# <br />");
return arg1 * arg2;
}
public boolean function subtract(numeric arg1, numeric arg2){
echo("You are trying to subtract #arg1# and #arg2# <br />");
var math = new math();
var result = math.add(arg1, arg2);
echo("The result was #result# <br />");
return arg1 - arg2;
}
}
<cfscript>
basic = new basic().something().was().here();
writeDump(basic);
</cfscript>
<cfscript>
dsl = new dsl().get();
</cfscript>
<cfscript>
math = new mathDecorator();
math.add(5, 7);
math.multiply(2, 10);
math.subtract(20, 6);
</cfscript>
<cfscript>
math = new mathDecoratorBasic();
math.add(5, 7);
math.multiply(2, 10);
math.subtract(20, 6);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment