Add properties() and methods() calls

This commit is contained in:
Enrico Lumetti 2021-05-06 23:03:07 +02:00
parent c9da63730b
commit bd2abeae3b
1 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,5 @@
clear;
% instantiate an object of type BasicClass (see BasicClass.m) % instantiate an object of type BasicClass (see BasicClass.m)
obj = BasicClass; obj = BasicClass;
@ -15,6 +17,12 @@ obj.roundOff();
v = BasicClass(42); v = BasicClass(42);
assert(v.Value == 42); assert(v.Value == 42);
% all properties can be enumerated
assert(isequal(properties(v), {'Value'}'));
% and all methods
assert(isequal(methods(v), {'BasicClass', 'multiplyBy', 'plus', 'roundOff'}'));
% object arrays are presto supported % object arrays are presto supported
objs(1) = BasicClass(44); objs(1) = BasicClass(44);
objs(2) = BasicClass(33); objs(2) = BasicClass(33);
@ -26,7 +34,7 @@ assert(isequal( [objs.Value], [44 33] ));
assert(isequal( {objs.Value}, {44, 33} )); assert(isequal( {objs.Value}, {44, 33} ));
% operator overloading % operator overloading
obj + objs(1); v + v;
% also works for object arrays % also works for object arrays
[objs] + [objs] [objs] + [objs];