Live data from Hacker News

What do you call this in Ruby?

github.com

41–50 of 69 posts

Re: What do you call this in Ruby?

#42

Meanwhile: Mathematica 10.0 for Mac OS X x86 (64-bit) Copyright 1988-2014 Wolfram Research, Inc. In[1]:= FullForm[x->y*z^w] Out[1]//FullForm= Rule[x, Times[y, Power[z, w]]] In[2]:= x\[UnionPlus]y\[RightTee]z Out[2]= x ⊎ y ⊢ z There's no reason your programming language shouldn't be able to tell you what these things are called in English without an external reference.

Or is there? queue x-files theme song

Re: What do you call this in Ruby?

#44

'!!' -> "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…

One typical use for !! in JavaScript or Ruby is where a function/method returns a boolean value that indicates the presence or absence of an object.

You could just use:

  return myObject;
Since that value will be truthy or falsy, any code that tests it will generally work, as your if statement example demonstrates.

But there are two advantages to doing this instead:

  return !! myObject;
1) Now you are returning an actual boolean value, not just a truthy/falsy value.

2) Sometimes more importantly, you are now releasing this function's reference to the object, instead of possibly keeping that reference around much longer than needed and preventing it from being garbage collected.

Re: What do you call this in Ruby?

#46
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:

Can someone explain to me, why this is not appropriate?
Post reply on HN