Test your knowledge of core Ruby concepts
Posted on
August 8, 2017
How much do you know about the Ruby programming language?

When it comes to general purpose, object-oriented programming languages, one of the most popular in the past few years is Ruby. Strongly influenced by Perl, Ada, Lisp, and others, Ruby has a strong focus on simplicity and productivity. As of this writing, 2.4.0 is the most recent release and it is both embraced and supported by a strong developer community.

What follows is a self-test of 25 questions all based on the core Ruby language with topics ranging from trivial to complicated. The answers appear at the end of the questions. In all cases, pick the best answer(s) to each question. Good luck!

1. With Ruby, which of the following methods can be used to report errors?
A. register
B. call
C. raise
d> convey

2. Which method in Ruby is used to read characters typed in by the user at the terminal?
A. store
B. read
C. key
D. gets

3. You are looking at the code of another programmer and see where they are using the super keyword with no arguments. The results of this is:
A. Operations will cease and the status of all variables will be either recorded or displayed on the terminal
B. Ruby sends a message to the parent object to invoke a method of the same name as that which caused super to be invoked
C. An endless loop will occur in which the method continuously calls itself until Ctrl+C is used to break the loop
D. All previous arguments are cleared and the routine uses the next set of values

4. You need a snippet of code to check a condition and see breakerswitch is set to on (a very rare condition) and immediately terminate if it is. As long as it is any other value, the rest of the program should continue to execute. What should you use in Ruby for this conditional?
A. unless
B. except
C. without
D. aside

5. Within Ruby, you need to format a sequence as a floating point decimal number. Which of the following indicates the data is to be used in that format?
A. %f
B. %n
C. %i
D. %p

6. A coworker is having difficulty running some scripts that another wrote in Ruby and you suspect he may have an older interpreter on his laptop. Which command can be used to reveal which version of Ruby interpreter is installed on the machine?
A. ruby -n
B. ruby -t
C. ruby -v
D. ruby -z

7. Which of the following is the primary difference between the puts and print methods in Ruby?
A. print adds a newline at the end of the string
B. puts adds a newline at the end of the string
C. print works with version 1.x and puts works with version 2.x
D. They are synonyms: there is no difference.

8. You have a handful of methods that you only want to be called from within the class where they are defined. In Ruby, wat can be used to accomplish this?
A. personal
B. covert
C. restricted
D. private

9. The name of a constant in Ruby:
A. Begins with an uppercase letter
B. Begins with a number
C. Includes only uppercase letters
D. Must include an underscore

10. Which method can be used with any Ruby object to show aspects of that object that don't typically appear in program output and is helpful in debugging?
A. examine
B. check
C. inspect
D. review

11. With Ruby, which of the following is used to end a case conditional?
A. end
B. esac
C. /case
D. \esac

12. Which of the following keywords are used in Ruby to define a method?
A. express
B. declare
C. define
D. def
E. label
F. term

13. With Ruby, which prefix do you use to define a character as a string delimiter?
A. //
B. %
C. #
D. {

14. Which of the following will create an output display similar to the following?

A. puts "Kristin", "Evan", "Spencer"
B. puts "Kristin" "Evan" "Spencer"
C. puts "Kristin"; "Evan"; "Spencer"
D. puts "Kristin" + "Evan" + "Spencer"

15. Within Ruby, which of the following methods is used to create a new directory?
A. Dir
B. Mkdir
C. Dir.mkdir
D. CreateDirectory
E. MakeDir
F. Make

Please visit GoCertify to attempt the remaining 10 questions of this quiz.


1. C
2. D
3. B
4. A
5. A
6. C
7. B
8. D
9. A
10. C
11. A
12. D
13. B
14. A
15. C

About the Author

Emmett Dulaney is a professor at Anderson University and the author of several books including Linux All-in-One For Dummies and the CompTIA Network+ N10-008 Exam Cram, Seventh Edition.

Posted to topic:

Important Update: We have updated our Privacy Policy to comply with the California Consumer Privacy Act (CCPA)

CompTIA IT Project Management - Project+ - Advance Your IT Career by adding IT Project Manager to your resume - Learn More