Ruby - Functional Patterns in Ruby
What will this Ruby code print?
p1 = Proc.new { |x| x * 3 }
p2 = Proc.new { |y| y - 4 }
p3 = p2 >> p1
puts p3.call(5)p1 = Proc.new { |x| x * 3 }
p2 = Proc.new { |y| y - 4 }
p3 = p2 >> p1
puts p3.call(5)p3 = p2 >> p1 means p3.call(x) = p1.call(p2.call(x)).p2.call(5) = 5 - 4 = 1, then p1.call(1) = 1 * 3 = 3.p3 = p2 >> p1, so first p2, then p1. So output is 3.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions