Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

After 20 years of Ruby I didn't know (or didn't remember) that next can have an argument. I looked it up. Thanks.

BTW, I never liked the _N arguments. Too cryptic. They make me stop and think on details instead of just read the code and concentrate on the important stuff.

  x.map {¦n¦ n + 3}.sum
is immediately clear but I guess that it's very subjective.


Such details are so subjective even a same person could change his/her mind about it and change it back later... I think they did a safe job of adding this _N feature though, since it's not allowed all the time. It felt like a missing feature because you could do map(&:to_i) but needed a parameter for something simple like map { |x| x == 5 }.

The `next` keyword is interesting in Ruby. It can be used as an explicit return for blocks. In javascript, for comparison, there is a `continue` for standard loops, but non-standard blocks don't exist so they are functions and require the use of the return keyword (except for single-instruction arrow functions). And implicit returns or nexts simply don't exist in js.


In 3.4 you can now do

  x.map { it + 3 }.sum 
which I'm still getting used to


Even the same customer has projects with Ruby ranging from 2.7 to 3.4 so I'm using the oldest possible syntax. The changes in keyword args hit hard some projects. Luckily not the one I'm working on most of my time.


You also find `it` in Kotlin.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: