31. What is the main difference between instance_eval and class_eval in Ruby? A. instance_eval evaluates code within the context of a method, while class_eval evaluates code within the context of a block B. instance_eval evaluates code within the context of a block, while class_eval evaluates code within the context of a method C. instance_eval evaluates code within the context of an object, while class_eval evaluates code within the context of a class D. instance_eval evaluates code within the context of a class, while class_eval evaluates code within the context of an object Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C No explanation is given for this question Let's Discuss on Board
32. What is the purpose of the prepend method in Ruby? A. Adds a method to the end of a class definition B. Adds a module to the inheritance chain after the class itself C. Adds a method to the beginning of a class definition D. Adds a module to the inheritance chain before the class itself Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board
33. In Ruby, what does it mean to "freeze" an object? A. Prevents further modifications to the object's state B. Locks the object's methods so they cannot be overridden C. Forces the object to release all resources allocated to it D. Prevents the object from being garbage collected Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A No explanation is given for this question Let's Discuss on Board
34. What is the purpose of the BasicObject class in Ruby? A. It is a special class used for metaprogramming purposes B. It is a module that defines common utility methods for all Ruby objects C. It provides a set of basic methods that all Ruby objects inherit D. It serves as the root of the Ruby class hierarchy Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board
35. Which method is commonly used to convert an object into its string representation in Ruby? A. to_str B. stringify C. to_s D. convert_to_string Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C No explanation is given for this question Let's Discuss on Board
36. What is the purpose of the Object#tap method in Ruby? A. It evaluates a block of code within the context of the object B. It allows you to perform operations on an object and return the object itself C. It raises an exception if the object is nil D. It evaluates a block of code within the context of the object Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B No explanation is given for this question Let's Discuss on Board
37. What does the term "lazy evaluation" refer to in Ruby? A. Repeatedly evaluating a computation until the desired result is obtained B. Storing the result of a computation for future use C. Delaying the execution of a computation until the result is needed D. Evaluating a computation as soon as it is defined Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C No explanation is given for this question Let's Discuss on Board
38. What is the purpose of the Enumerable#reduce method in Ruby? A. It filters elements of a collection based on a given condition B. It transforms each element of a collection using a given block C. It sorts elements of a collection based on a given criteria D. It combines all elements of a collection into a single value using a binary operation Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board
39. What is the significance of using the include? method in Ruby's Enumerable module? A. It checks if a collection includes a specific element B. It includes a module into the current class C. It iterates over each element of a collection D. It creates a new collection by filtering elements based on a given condition Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A No explanation is given for this question Let's Discuss on Board
40. Which method is used to convert a hash into an array of key-value pairs in Ruby? A. flatten B. values C. keys D. to_a Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D No explanation is given for this question Let's Discuss on Board