Hacker News new | ask | show | jobs
by elif 537 days ago
nested_example = [1, 2, 3, 4, 5].map do

  [it, (1..it).map { it * it }]
end

Has an ambiguity, so you just add |x| to one of them..

nested_example = [1, 2, 3, 4, 5].map do |x|

  [x, (1..x).map { x * it }]
end

Seems like a mental over complication of a non-issue to me.

2 comments

Implicit `it` shadows in other languages like Kotlin just like any other variable scope, and I really can’t say I’ve ever had it be a problem (implicit receivers, on the other hand, can be a right pain in the ass in poorly designed libraries and can I just say Gradle can go right to hell for it).
It’s a nonissue in small projects, but I’m not sure I agree that `{ x * it }` is easy to reason about when coming back to this block in 6 months. It’s mostly something that I’ve seen bite engineers during refactoring.