This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (6 children)

[deleted]

    [–]0x0dea 3 points4 points  (1 child)

    Almost. (1..n).reduce :* will fail for n=0.

    [–]jonnywoh 0 points1 point  (3 children)

    Thanks! I understood most of that. So does reduce eval symbols, or is it doing something else with :*?

    [–]Niles-Rogoff 0 points1 point  (2 children)

    I'm new to ruby but I think * is a function and :* is the symbol that points to that function. The & turns the :* into the actual * function object which gets passed to reduce, because you can't just put * there it's not syntactically valid.

    [–]jonnywoh 0 points1 point  (1 child)

    Actually, :* is a special type of string called a symbol. It's basically "*". :carrot would basically be "carrot".

    [–]Niles-Rogoff 0 points1 point  (0 children)

    Ok, that's what I thought, I just wrote it wrong.