-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby_control_structures.rb
35 lines (30 loc) · 1020 Bytes
/
ruby_control_structures.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# HackerRank is written in RoR and we have various classes defined in it. Some of them are
# Hacker
# Submission
# TestCase
# Contest
# etc.
# You have been given a function where an object which may or may not be of the above mentioned type is sent as an argument. You have to use the case control structure in Ruby to identify the class to which the object belongs and print the following output:
# if Hacker, output "It's a Hacker!"
# if Submission, output "It's a Submission!"
# if TestCase, output "It's a TestCase!"
# if Contest, output "It's a Contest!"
# for any other object, output "It's an unknown model"
# Note
# use case (switch statement of Ruby)
# use puts for printing
# Ruby Docs on case
def identify_class(obj)
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
puts "It's an unknown model"
end
end