Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Not sure if you're aware, but I noticed a couple of potential issues with your solution.
\Z
matches trailing newlines, although not anything beyond that. (\z
doesn't!) And\w
equates to[a-zA-Z0-9_]
as well, so you'll accidentally consider an underscore to be an alphanumeric character, which you might not want!:-)
It's leaning on functionality of
Symbol#to_proc
to do it. There's a few different pieces that make it up, and http://www.jacopretorius.net/2012/01/symbolto_proc-in-ruby.html seems to be a good in depth writeup of it.In short though:
&foo
in arguments passesfoo
as a block to the method as if you'd done{ foo.call }
. If foo isn't a proc, it callsto_proc
on it first.Symbol#to_proc
is implemented and creates a proc that sends the symbol to the block argument. That is:capitalize.to_proc
returns a proc (block) equivilent to{ |arg| arg.capitalize }
[].map { |element| element.capitalize }
can be written as[].map(&:capitalize)
and it returns the same result.