Procs and Lambdas • Exercise 3/4

Block to Proc

00:00
0
20 points

Instructions

Create a function apply_twice that takes a value and a block,
then applies the block twice to the value.

Use &block to capture a block as a Proc parameter:
ruby
def my_method(&block)
block.call(value) # block is now a Proc
end

Example:
```ruby
apply_twice(2) { |x| x * 3 }

First: 2 * 3 = 6

Second: 6 * 3 = 18

=> 18

Your Code

Results

Click "Run Tests" to see results