I am currently working on a refactor of a method I previously created
but have reached a snag. I want to replace a set of nested if statements
with a cleaner case statement.
The purpose of the method is to return the average value of a list,
it should support 5 different data types with different rules for each:
Real values are simply returned
Integer values are converted into Real values
Vector 2 and Vector 3 values are treated as the average of their axes
String values are treated as their length
This is the refactor as it stands now, along with my current issue:
This is an example of how it may be called, using every compatible data type:
From left to right -
Real, Integer, Vector2, Vector3, String
The result of this should equal to 1 but currently as all comparisons fail, the result is 0
I believe that this a scenario where the case statement cannot be used as, unlike class_of?, it does not explicitly compare the class of the item to each provided data type and instead treats each item generically.
Is what I am wanting achievable with a case statement or will I need to resort to using nested if statements like this?
Perhaps there is a better way than both of the above.