








































































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!









































































Question 1. Who is the creator of the Ruby programming language? A) Guido van Rossum B) James Gosling C) Yukihiro "Matz" Matsumoto D) Dennis Ritchie Answer: C Explanation: Yukihiro "Matz" Matsumoto designed and developed Ruby, focusing on programmer happiness and productivity. Question 2. Which key philosophy does Ruby emphasize for programmers? A) Strict typing B) Programmer happiness C) Low-level memory management D) Compilation speed Answer: B Explanation: Ruby's design centers around making programming enjoyable, prioritizing programmer happiness. Question 3. What is the file extension for Ruby source code files? A) .rb B) .py C) .js D) .java Answer: A Explanation: Ruby files typically use the .rb extension.
Question 4. How do you start the Interactive Ruby Shell (IRB) on the command line? A) ruby shell B) irb C) ruby - i D) rbsh Answer: B Explanation: Typing 'irb' in the terminal starts the Interactive Ruby Shell. Question 5. Which method outputs text and adds a newline at the end in Ruby? A) print B) puts C) echo D) write Answer: B Explanation: 'puts' prints the provided text followed by a newline. Question 6. How do you write a single-line comment in Ruby? A) // B) -- C) # D) /* */ Answer: C Explanation: Ruby uses the '#' symbol for single-line comments. Question 7. Which block is used for multi-line comments in Ruby?
Answer: B Explanation: String interpolation is performed using '#{}' inside double-quoted strings. Question 11. How do you define a local variable in Ruby? A) $local B) @local C) local_var D) @@local Answer: C Explanation: Local variables start with a lowercase letter or an underscore. Question 12. How do you define an instance variable in Ruby? A) $variable B) @variable C) variable D) @@variable Answer: B Explanation: Instance variables are prefixed with '@'. Question 13. What is the naming convention for constants in Ruby? A) Uppercase letters B) Lowercase letters
C) Prefixed with $ D) Prefixed with @ Answer: A Explanation: Constants begin with an uppercase letter. Question 14. Which variable type uses the @@ prefix in Ruby? A) Local variable B) Instance variable C) Class variable D) Global variable Answer: C Explanation: Class variables are prefixed with '@@'. Question 15. Which variable type uses the $ prefix in Ruby? A) Local variable B) Instance variable C) Class variable D) Global variable Answer: D Explanation: Global variables are prefixed with '$'. Question 16. What is the scope of a local variable in Ruby? A) Global B) Class-wide C) Limited to the block, method, or class where it is defined
Answer: B Explanation: String interpolation evaluates the expression inside '#{}', so '2 + 2' becomes 4. Question 20. Which class represents an integer in Ruby? A) Float B) Integer C) Number D) Fixnum Answer: B Explanation: Ruby uses the Integer class for whole numbers. Question 21. What does the '' operator do in Ruby? A) Addition B) Subtraction C) Multiplication D) Exponentiation Answer: D Explanation: '' is used for raising a number to the power of another. Question 22. Which method converts a string "123" into an integer in Ruby? A) to_f B) to_s C) to_i D) to_a Answer: C
Explanation: 'to_i' converts a string to an integer. Question 23. What is the result of '10 / 3' in Ruby? A) 3. B) 3 C) 10 D) 0 Answer: B Explanation: Integer division returns an integer result, truncating the decimal part. Question 24. Which method returns the number of characters in a String? A) size B) length C) count D) chars Answer: B Explanation: The 'length' method gives the total number of characters in a string. Question 25. How do you check if a string contains a specific substring in Ruby? A) has? B) contains? C) include? D) substring? Answer: C Explanation: 'include?' checks if a substring exists within a string.
Question 29. Which method replaces the first occurrence of a pattern in a string? A) gsub B) sub C) replace D) swap Answer: B Explanation: 'sub' replaces only the first occurrence; 'gsub' replaces all. Question 30. How do you create a multi-line string in Ruby? A) Using triple quotes B) Using brackets C) Here Document syntax D) Semicolon Answer: C Explanation: The Here Document syntax (<<- or <<) allows multi-line strings. Question 31. What does 'nil' represent in Ruby? A) Zero B) False C) No value or empty D) Undefined Answer: C Explanation: 'nil' is Ruby's way of representing "no value" or "empty". Question 32. What evaluates to false in Ruby conditional statements?
A) 0 and nil B) Only nil C) Only false D) nil and false Answer: D Explanation: Only 'nil' and 'false' are considered falsey in Ruby; all other values are truthy. Question 33. Which class does 'nil' belong to in Ruby? A) NilObject B) NilClass C) FalseClass D) Object Answer: B Explanation: 'nil' is an instance of the NilClass. Question 34. What is a symbol in Ruby? A) A string with extra features B) An immutable identifier C) A numeric constant D) A special variable Answer: B Explanation: Symbols are immutable, reusable identifiers often used as hash keys. Question 35. Which syntax creates a symbol in Ruby? A) "symbol"
C) append D) insert Answer: A Explanation: 'push' or '<<' adds elements to the end of an array. Question 39. Which method removes the last element of an array? A) shift B) pop C) delete D) remove Answer: B Explanation: 'pop' removes and returns the last element. Question 40. How do you access the first element of an array? A) array.first B) array[1] C) array[0] D) array.begin Answer: C Explanation: Arrays are zero-indexed, so the first element is at index 0. Question 41. Which method removes the first element of an array? A) pop B) shift C) delete
D) remove Answer: B Explanation: 'shift' removes and returns the first element of an array. Question 42. Which method combines all elements of an array into a string separated by a delimiter? A) join B) combine C) glue D) merge Answer: A Explanation: 'join' concatenates array elements into a single string. Question 43. Which method returns a sorted version of an array? A) order B) sort C) arrange D) organize Answer: B Explanation: 'sort' returns a new array sorted in ascending order. Question 44. What does the 'uniq' method do to an array? A) Removes nil values B) Removes duplicate elements C) Sorts the array D) Splits the array
Explanation: 'keys' returns an array of all hash keys. Question 48. How do you delete a key-value pair from a hash? A) remove B) delete C) pop D) clear Answer: B Explanation: 'delete' removes a key-value pair from a hash. Question 49. How do you merge two hashes in Ruby? A) combine B) append C) merge D) join Answer: C Explanation: 'merge' combines two hashes, returning a new hash. Question 50. How do you create an inclusive range from 1 to 5? A) 1 to 5 B) 1 ... 5 C) 1.. D) [1,5] Answer: C Explanation: '1..5' creates a range including both endpoints.
Question 51. How do you create an exclusive range from 1 to 5? A) 1.. B) 1... C) 1 to 5 D) 1, Answer: B Explanation: '1...5' creates a range from 1 up to, but not including, 5. Question 52. Which statement is used for conditional branching in Ruby? A) if-else B) switch C) case D) select Answer: A Explanation: Ruby uses 'if', 'elsif', and 'else' for conditional branching. Question 53. Which statement provides multi-way branching in Ruby? A) if B) switch C) case D) branch Answer: C Explanation: The 'case' statement allows multi-way branching.
A) while B) until C) for D) do Answer: B Explanation: 'until' runs until its condition is true. Question 58. Which keyword stops the current loop iteration and exits the loop? A) stop B) break C) exit D) continue Answer: B Explanation: 'break' exits the loop immediately. Question 59. Which keyword skips the rest of the current loop iteration and continues to the next one? A) skip B) next C) continue D) redo Answer: B Explanation: 'next' skips to the next iteration in a loop. Question 60. Which keyword restarts the current iteration of a loop in Ruby? A) repeat
B) redo C) again D) continue Answer: B Explanation: 'redo' restarts the current loop iteration. Question 61. Which iterator runs a block of code for each element in an array? A) each B) for C) iterate D) loop Answer: A Explanation: 'each' applies a block to every element in a collection. Question 62. Which numeric iterator executes a block a specified number of times? A) repeat B) times C) for D) each Answer: B Explanation: 'times' runs the block the specified number of times. Question 63. Which numeric iterator counts upwards from a starting value to an ending value? A) upto B) downto