result = " hello world ".strip.upcase.reverse puts result
The strip method removes spaces at the start and end, upcase converts all letters to uppercase, and reverse reverses the string. So the final output is the reversed uppercase string without spaces.
numbers = [1, 2, 3, 4, 5] result = numbers.select(&:odd?).map { |n| n * 10 }.join(",") puts result
select(&:odd?) picks odd numbers [1,3,5]. map { |n| n * 10 } multiplies each by 10 giving [10,30,50]. join(",") makes a string "10,30,50".
result = "123abc".to_i.to_s.reverse puts result
to_i converts string to integer 123, to_s converts back to string "123", then reverse reverses it to "321". No error occurs.
Option A: "HELLO".upcase! returns nil because the string is already uppercase (no mutation). Then nil.reverse raises NoMethodError. Options B, C, and D execute without error.
text = "Ruby is fun and powerful"Option D uses select to filter words with length > 3 ("Ruby", "powerful"), then count returns 2. Option D raises NoMethodError (filter undefined in standard Ruby). Option D maps to booleans and count (no arg) returns array size 5. Option D works (2) but is less idiomatic than enumerator methods.