Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Blocks Ruby Blocks Calling Blocks

Brian Fallon
Brian Fallon
4,733 Points

Need help with the final objective in the Ruby Blocks course

I need assistance with the final objective in ruby blocks. It says using the call method, change the header in the print header file.

Is there supposed to be a call method present in here? I did not see or hear any mention of a built in call method throughout the course thus far so I am a bit confused with what it is asking. The code should be attached.

calling_blocks.rb
def print_header(&block)
  puts "-- Header --"

  puts "-- End of Header --"
end
Brian Fallon
Brian Fallon
4,733 Points

Never mind, this can be closed. I just remembered the block.call method.

Why not post up your own solution? Would help other students!

1 Answer

Brian Fallon
Brian Fallon
4,733 Points
def print_header(&block)
  puts "-- Header --"
  block.call
  puts "-- End of Header --"
end

I had forgotten about the block.call method, simple mistake.

MOD: Moved to answer to be marked as Best Answer to close it.