Special Offer! Black Friday + Cyber Monday Sale! Extra 20% OFF - Ends In Coupon code: HELLO20OFF
Increase your chances of passing the Ruby Association Ruby-Programmer-Gold exam questions on your first try. Practice with our free online Ruby-Programmer-Gold exam mock test designed to help you prepare effectively and confidently.
Analyze the following Ruby code snippet in the context of class design and instance variable management:class Book attr_reader :title, :author @@total_books = 0 def self.total_books @@total_books end def initialize(title, author) @title = title @author = author @@total_books += 1 endendclass Library attr_reader :books def initialize @books = [] end def add_book(book) @books
Analyze the following Ruby code snippet that utilizes regular expressions for string processing:class EmailExtractor EMAIL_REGEX = /(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b)/ def self.extract_from(text) text.scan(EMAIL_REGEX).flatten endend text1 = "Contact us at [email protected] for assistance"text2 = "Send your feedback to: [email protected] and [email protected]"text3 = "No emails here!" result1 = EmailExtractor.extract_from(text1)result2 = EmailExtractor.extract_from(text2)result3 = EmailExtractor.extract_from(text3) What will be the values of result1, result2, and result3, respectively?
In Ruby, effectively using blocks is essential for controlling flow and data processing. Review the following Ruby code snippet:numbers = [1, 2, 3, 4, 5]sum = 0numbers.each { |number| sum += number }squared_numbers = numbers.map { |number| number ** 2 } Based on this code, which two of the following statements are correct about the blocks used in the context of the each and map methods?
Review the following Ruby code snippet in the context of class inheritance and method access control:class Product def initialize(name, price) @name = name @price = price end private def price @price endendclass Electronic < Product def discount_amount(discount_percentage) price * discount_percentage / 100.0 end def discounted_price(discount_percentage) price - discount_amount(discount_percentage) endendelectronic_item = Electronic.new("Laptop", 1000)result = electronic_item.discounted_price(20)What will be the value of result?
Consider the following Ruby code snippet that incorporates the use of refinements:module StringAdjustments refine String do def emphasize "#{self}!" end endend class Writer using StringAdjustments def emphasize_statement(statement) statement.emphasize endend writer = Writer.newexternal_statement = "Hello".emphasize result1 = writer.emphasize_statement("Hello")result2 = external_statement What will be the values of result1 and result2, respectively?
© Copyrights FreeMockExams 2025. All Rights Reserved
We use cookies to ensure that we give you the best experience on our website (FreeMockExams). If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the FreeMockExams.