

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CMSC 330, Practice Problems 1
i. What is the output of the following Ruby program? a = [“c”, “b”, “a”] puts a b = a a.sort! puts b j. What is the output of the following Ruby program? a = CMSC 330 CMSC 351” b = a.scan(/[A-Z]+/) puts b a.scan(/[0-9]+ [A-Z]+/) { |x| puts x } k. What is the output of the following Ruby program? a = {4 => 6, 5 => 7} puts a[4] puts a[6] puts a.values l. What is the output of the following Ruby program? h = Hash.new(0) h["a"] = h["b"] h["b"] = 7 h["c"] += 2 puts "#{h["a"]} #{h["b"]} #{h["c"]}" m. What is returned by “file = File.new(filename, "r"); lines = file.readlines( );”? n. What is returned by “x = ARGV[0];”? o. Write a Ruby function foo that takes a code block and executes it twice.