Skip to content

Comment on Haskell style list comprehensions in Rubyparent

Comments

Specifically, it is monkey patching the unary - and + operators on array, and has a clever global method missing.

The unary operators `def -@` gets called when you do something like: `-[1,2,3]`.

So in the example code at the bottom, it's doing `bar =+ [x | x <- [1..3]]` that's better parsed as `bar = +[x | x <- [1..3]]` (note the spacing difference).

Hacking unary operators has a long history in silliness in ruby. See also: https://github.com/jicksta/superators

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.