Learn

See? Even though this block business has a little more going on under the hood than we thought, it’s still pretty straightforward.

Now that we know how methods accept blocks using the yield keyword, let’s define our own method and pass it a block!

Instructions

1.

Define your own method, double, that accepts a single parameter and yields to a block. Then call it with a block that multiplies the number parameter by 2. You can double any number you like!

puts the result in order to see your yield in action!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?