Aer/tests/closure_test.aer

37 lines
633 B
Plaintext
Raw Normal View History

class Operations {
public callback ops(int $x, int $y, string $op){
switch($op) {
case 'ADD':
return int() using ($x, $y) {
return $x + $y;
};
break;
case 'SUB':
return int() using ($x, $y) {
2019-04-17 10:08:03 +02:00
return $x - $y;
};
break;
default:
return string() {
return 'Operation is not supported by class.';
};
}
}
}
class Program {
public void main() {
callback $fn;
object $op = new Operations();
$fn = $op->ops(6, 7, 'ADD');
print($fn() + "\n");
$fn = $op->ops(6, 2, 'SUB');
print($fn() + "\n");
$fn = $op->ops(6, 7, 'MUL');
print($fn() + "\n");
}
}