Skip to content

Instantly share code, notes, and snippets.

@stalcottsmith
Created June 13, 2015 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stalcottsmith/8baf5437da80f79470a1 to your computer and use it in GitHub Desktop.
Save stalcottsmith/8baf5437da80f79470a1 to your computer and use it in GitHub Desktop.
Is there an anonymous recursion alternative in Ruby? This is the best I could come up with which requires naming.
func = -> (node, func) {
node.children.each do |node|
# do something
func.call(node, func)
end
}
func.call(root, func)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment