Skip to content

Instantly share code, notes, and snippets.

@rickhull
Created July 20, 2010 16:49
Show Gist options
  • Save rickhull/483210 to your computer and use it in GitHub Desktop.
Save rickhull/483210 to your computer and use it in GitHub Desktop.
# how to define section(heading, &block) so it:
# prints out some "header" formatting, e.g. "\n<hr>#{heading}\n"
# and then indents ALL OUTPUT originating from its block
#
# e.g.
section 'Nerf herding' do
herd = []
10.times { herd << rand(5) }
puts herd.last
end
section 'Hot grits' do
puts 'with extra sizurp'
section 'natalie portman' do
puts 'hello from slashdot'
section 'beowulf cluster' do
puts 'could you imagine?'
end
end
end
section 'Github rules!' do
puts '1. Do not talk about github'
end
puts "DONE"
######### DESIRED OUTPUT BELOW #########
--------------------------------------------------------
Nerf herding
3
--------------------------------------------------------
Hot grits
with extra sizurp
------------------------------------------------------
natalie portman
hello from slashdot
----------------------------------------------------
beowulf cluster
could you imagine?
--------------------------------------------------------
Github rules!
1. Do not talk about github
DONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment