We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This problem statement is extremely misleading and needs to be rewritten.
As it is stated, we are lead to believe that Hacker, Submission, TestCase, and Constants are all separate classes inheriting from the same superclass. This means that the following solution should work:
caseobjwhenHacker,Submission,TestCase,Contestputs"It's a #{obj.class}!"elseputs"It's an unknown model"end
However, it fails test case 1. Moreover, some of the solutions listed below suggest that Hacker, Submission, TestCase, and Constant are really integer constants euqivalent to to 1, 2, 3, and 4.
Obviously, using integer constants instead of subclasses goes against the problem definition (as currently written). While it will work for basic solutions checking each class type separately, more elaborate solutions taking advantage of the obj.class value will fail. Moreover, testing one solution using subclasses and another using integer constants is extremely misleading; if our solution is expected to work for both situations, the problem statement should explicitly say so.
Cookie support is required to access HackerRank
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 →
This problem statement is extremely misleading and needs to be rewritten.
As it is stated, we are lead to believe that Hacker, Submission, TestCase, and Constants are all separate classes inheriting from the same superclass. This means that the following solution should work:
However, it fails test case 1. Moreover, some of the solutions listed below suggest that Hacker, Submission, TestCase, and Constant are really integer constants euqivalent to to 1, 2, 3, and 4.
Obviously, using integer constants instead of subclasses goes against the problem definition (as currently written). While it will work for basic solutions checking each class type separately, more elaborate solutions taking advantage of the obj.class value will fail. Moreover, testing one solution using subclasses and another using integer constants is extremely misleading; if our solution is expected to work for both situations, the problem statement should explicitly say so.