You are viewing a single comment's thread. Return to all comments →
If you're doing the same thing for each case, a case statement doesn't really make sense in my opinion.
Here's a predicate that includes all of the conditions:
[Hacker, Submission, TestCase, Contest].any? { |clazz| obj.is_a? clazz }
You can use string interpolation (like in truesdell_trent1's comment here ) or just concatenation (with obj.class.name) to output the class names.
obj.class.name
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby Control Structures - Case (Bonus Question)
You are viewing a single comment's thread. Return to all comments →
If you're doing the same thing for each case, a case statement doesn't really make sense in my opinion.
Here's a predicate that includes all of the conditions:
You can use string interpolation (like in truesdell_trent1's comment here ) or just concatenation (with
obj.class.name
) to output the class names.