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?
2. Which method in Ruby is used to read characters typed in by the user at the terminal?
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?
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?
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?
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?
11. With Ruby, which of the following is used to end a case conditional?
12. Which of the following keywords are used in Ruby to define a method?
13. With Ruby, which prefix do you use to define a character as a string delimiter?
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?
Please visit GoCertify to attempt the remaining 10 questions of this quiz.