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.
Does a ternary operator not count as a conditional statement?
I took it as implied that I was recreating zip. Not re-using it.
Needs more test cases!
I wondered the same thing, until I saw everyone else doing it. I am only just learning ruby.
How can you call a function within its own function definition?
This comment is hidden because it contains spoiler information about the solution
Why does this work?
A little digging brought me to Stack Overflow (http://stackoverflow.com/questions/1961030/ruby-ampersand-colon-shortcut). It's a really cool functionality, and I'm glad I know it now!
Read up on the unary & operator. It's operating on the :capitalize symbol. Basically it's making the captialize method into a block.
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.I don't understand it. Doesn't Array#map accept a block as an argument? What is the syntax for "&:capitalize"?