Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.