Skip to content

Instantly share code, notes, and snippets.

@jordelver
Created October 8, 2014 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jordelver/6a375a1bf27c63cb0b5a to your computer and use it in GitHub Desktop.
Save jordelver/6a375a1bf27c63cb0b5a to your computer and use it in GitHub Desktop.
Ruby yield as a default parameter

Learnt this from Avdi Grimm's Ruby Tapas

def content_for(tag, content = yield)
  "<%s>%s</%s>" % [tag, content, tag]
end

content_for("p", "hi")
=> "<p>hi</p>"

content_for("p") { "hi" }
=> "<p>hi</p>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment