News for hackers. Stuff that matters.
Re:My Weird Ruby by baddox on Saturday March 07, 2015 @03:11AM (#9161359)
That seems okay to me. JavaScript works well enough with that behavior.
Re:My Weird Ruby by i_s on Sunday March 08, 2015 @12:04PM (#9165994)
Re:My Weird Ruby by delsalk on Saturday March 07, 2015 @05:22AM (#9161517)
Works well meaning don't use functional calls at all if you want to escape from them.
Re:My Weird Ruby by baddox on Saturday March 07, 2015 @09:48PM (#9164274)
I've just never encountered that use case in Ruby code, and to me it feels like really bad style. You can use .find to find the first element that matches a block, then return that item (if one exists).
Re:My Weird Ruby by delsalk on Saturday March 07, 2015 @09:57PM (#9164299)
It doesn't look like fantastic Ruby code, you're right. I just wouldn't agree that JS "works well" when it comes to their somewhat afterthought functional iterators.
Re:My Weird Ruby by baddox on Sunday March 08, 2015 @12:44AM (#9164714)
What doesn't work well? The only thing I can think of, which comes up on occasion, is that you can't manually stop iteration in forEach without ugly tricks like throwing and catching an exception. I actually wanted that behavior for the first time recently, so I just used JQuery's each which lets you stop iteration by returning false. I'm assuming other JS utility libraries like underscore provide something similar.
Re:My Weird Ruby by masklinn on Saturday March 07, 2015 @05:18AM (#9161510)
Javascript iteration primitive isn't block-based.
Re:My Weird Ruby by picks_at_nits on Saturday March 07, 2015 @06:55AM (#9161638)
Ruby iteration primitive isn’t block based, either.
Re:My Weird Ruby by masklinn on Saturday March 07, 2015 @07:29AM (#9161685)
Of course it is. `for a in b` desugars to `b#each`, not the other way around.
Re:My Weird Ruby by picks_at_nits on Saturday March 07, 2015 @07:33AM (#9161694)
How do “while” and “until” desugar? Kernel#loop?
Re:My Weird Ruby by chrisseaton on Saturday March 07, 2015 @10:39AM (#9162008)
Those are two rare exceptions and you're right they don't desugar.
Re:My Weird Ruby by picks_at_nits on Saturday March 07, 2015 @11:45AM (#9162240)
Those are not “exceptions” to Ruby’s primitives, those are Ruby’s primitives. Things that desugar to methods aren’t primitives.

The thing is, they’re rare in practice for cultural reasons.