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.
he is using interpolation within the double quoted strings. Hence obj.class will be processed or evaluated first before it turns into a string. (respectively in order: "Hacker", "Submission", "TestCase", and then "Contest")
as soon as he grouped the whens in the case, it is almost as if he is saying
if obj == Hacker || obj == Submission || obj == TestCase || obj == Contest
puts "It's a #{obj.class}!"
else
puts "It's an unknown model"
Here is the unrefactored version
write your case control structure here
case obj
when Hacker
puts "It's a Hacker!"
when Submission
puts "It's a Submission!"
when TestCase
puts "It's a TestCase!"
when Contest
puts "It's a Contest!"
else
"It\'s an unknown model"
end
end
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 →
he is using interpolation within the double quoted strings. Hence obj.class will be processed or evaluated first before it turns into a string. (respectively in order: "Hacker", "Submission", "TestCase", and then "Contest")
as soon as he grouped the whens in the case, it is almost as if he is saying
if obj == Hacker || obj == Submission || obj == TestCase || obj == Contest puts "It's a #{obj.class}!" else puts "It's an unknown model"
Here is the unrefactored version
write your case control structure here
end