Live data from Hacker News

What do you call this in Ruby?

github.com

11–20 of 69 posts

Re: What do you call this in Ruby?

#11
post #5

Just added a PR for the spermy operator (~>).

For those wondering, here's the request: https://github.com/JuanitoFatas/what-do-you-call-this-in-rub...

Here's the response: Hi Christian, thanks for the Pull Request! But I think this is not appropriate rubygems/rubygems#124. :bow:

Re: What do you call this in Ruby?

#13

'!!' -> "truthy?"

! -> "not truthy". So !! means "not 'not truthy'" which is truthy.

Truthy is something that isn't exactly a true boolean but will equate to true(thy) when evaluated with this type of comparison. Things like undefined, null, and empty string will not be truthy.

More info on what's truthy (for JavaScript at least) is here http://james.padolsey.com/javascript/truthy-falsey/

edit: typically, if you want to test for truthy, you'll just evaluate it like so

if (my_object) { //truthy }else{ //not truthy }

Does anyone know a time when you'd use !! instead of just the object in the evaluation? I'm not a Ruby dev, so I don't know specific cases for needing !!

Re: What do you call this in Ruby?

#15

'!!' -> "truthy?"

! -> "not truthy". So !! means "not 'not truthy'" which is truthy. Truthy is something that isn't exactly a true boolean but will equate to true(thy) when evaluated with this type of comparison. Things like undefined, null, and empty string will not be truthy. More info on what's truthy (for JavaScript at least) is here http://james.padolsey.com/javascript/truthy-falsey/ edit: typically, if you want to test for truth…

Yep, I thought it was a common enough idiom in Ruby as well that it might belong on the list!

Re: What do you call this in Ruby?

#20
post #12

A select few operators (out of hundreds) for a single Haskell library: https://github.com/ekmett/lens/wiki/Operators (For full disclosure, the lens library is infamous for this.)

You are perfectly fine importing the module Control.Lens.Combinators[0], which has the full functionality of lens except the operators. There's nothing you can do with operators but can't do with normal functions named with words.

[0]: http://ekmett.github.io/lens/src/Control-Lens-Combinators.ht...

Post reply on HN