Complete the code to create a Proc that returns 'Hello'.
greet = Proc.new { [1] }The Proc should return the string "Hello". Using just the string "Hello" inside the block returns it.
Complete the code to call the Proc and print its result.
greet = Proc.new { "Hello" }
puts [1]To call a Proc in Ruby, use call(). This executes the Proc and returns its value.
Fix the error in the code to correctly create and call a Proc that adds 5 to a number.
add_five = Proc.new { |num| num [1] 5 }
result = add_five.call(10)
puts resultThe Proc should add 5 to the input number, so the plus operator + is correct.
Fill both blanks to create a Proc that checks if a number is even and call it with 8.
is_even = Proc.new { |n| n [1] 2 == 0 }
puts is_even.[2](8)== inside the block incorrectly.call method.The modulo operator % checks the remainder when dividing by 2. The Proc is called using call.
Fill all three blanks to create a Proc that multiplies a number by 3, call it with 7, and print the result.
triple = Proc.new { |x| x [1] 3 }
result = triple.[2]([3])
puts resultThe Proc multiplies by 3 using *. It is called with 7 using call, and the result is printed.