CIT 597 Quiz 8: Ruby
Fall 2008, David Matuszek Name_________________________________________
  1. (5 points) Which of Java's arithmetic operators are not available in Ruby?

  2. (5 points) What arithmetic operator does Ruby have that isn't available in Java?

  3. (10 points) List two ways in which Ruby's case statement differs semantically (that is, ignoring syntax differences) from Java's switch statement.



  4. (20 points) True or false:
    1. _____ Function calls sometimes need parentheses around the arguments.
    2. _____ if statements sometimes need parentheses around the condition.
    3. _____ if statements sometimes use the word then.
    4. _____ All function definitions belong to some class.
    5. _____ Functions may be overloaded.
    6. _____ Ruby's regular expressions are very similar to Perl's.
    7. _____ The range 1..5 includes the value 5.
    8. _____ [1..5] denotes an array with more than one element.
    9. _____ If a = [1, 2, 3], then a[500] = 'hello' is a valid statement.
    10. _____ When if is used as a statement suffix, end is not required.

  5. (10 points) Use the each iterator to print out all the elements of the array a, one per line.


  6. (5 points) What keywords does Ruby use in place of catch and finally?

  7. (20 points) In Ruby, how would you write:
    1. An instance variable "value"? ____________________
    2. A class variable "unique_id"? ____________________
    3. A global variable "limit"? ____________________
    4. A local variable "temp"? ____________________
    5. The symbol "summer"? ____________________

  8. (5 points) You can start an interactive Ruby session with the command _______________ .

  9. (5 points) What is printed by the following three lines?
           x = 12
          def foo; x = 8; yield; end
          foo { puts x }
  10. (15 points) What does each of the following methods do?
    1. chop

    2. chomp

    3. chomp!