Ruby Control Structures - Case (Bonus Question)

  • + 1 comment

    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.