Skip to content

Instantly share code, notes, and snippets.

@edward
Created October 26, 2008 15:08
Show Gist options
  • Save edward/19897 to your computer and use it in GitHub Desktop.
Save edward/19897 to your computer and use it in GitHub Desktop.
def make_sandwiches(however_many)
sandwiches = []
however_many.times do
sandwiches << make_sandwich { |sandwich| yield sandwich }
end
sandwiches
end
def make_sandwich
sandwich = "=======\n"
yield(sandwich)
sandwich << "=======\n\n"
puts sandwich
end
make_sandwich do |sandwich|
sandwich << "peanut\n"
sandwich << "butter\n"
sandwich << "jelly\n"
sandwich << "time\n"
end
make_sandwiches(3) do |sandwich|
sandwich << "bacon\n"
sandwich << "hamburger\n"
sandwich << "bacon\n"
sandwich << "cheese\n"
sandwich << "bacon\n"
end
def set_daily_special(&instructions)
@daily_recipe = instructions
end
set_daily_special do |sandwich|
sandwich << "green eggs\n"
sandwich << "ham\n"
end
def make_daily_special
make_sandwich { |sandwich| @daily_recipe.call(sandwich) }
end
make_daily_special
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment