Ruby ivars are already pretty confusing to folk who are new to programming and I think this will blur the line even more. What do y'all reckon?

I'm bit iffy on these default variable names in blocks which might land in 2.7
[1, 2, 3].map { @1 + 3 }
=> [4, 5, 6]


details: https://medium.com/%40baweaver ... 55fe4

Ruby ivars are already pretty confusing to folk who are new to programming and I think this will blur the line even more. What do y'all reckon?
 
 
My beef is totally with the choice of @ symbol not the feature. I think my issue is that I really like how `@foo` reminds me that I am reading/writing *state* i.e. `@foo` is 1) shared by other methods in my class, 2) will persist beyond after this method ends, 3) might be shared with code outside this class by something else in the class and these `@1` and friends kinda dilute that reminder. :shrug: It's nbd in the scheme of things
You already invited:

bart

Upvotes from:

I’m guessing it’s something a lot of devs will enable a cop to prevent it being use

Cristina Remoto

Upvotes from:

I don’t really see the problem this is trying to solve
`[1,2,3,4].map { |i| i + 1 }` vs. `[1,2,3,4].map { @admin + 1 }`

I save typing a few characters? (edited) 
and now instead of having a named variable I have a generic, order-dependent variable?

Shannon Miller

Upvotes from:

it's used a lot in the Elixir ecosystem;
`Enum.map([1,2,3,4], &(&1 + 5))` vs `[1,2,3,4].map { @admin + 5 }`

I think it would be better if it used the ampersand like in elixir, and like ruby uses for shorthanding methods for blocks (e.g. `[1,2,3,4].map(&:something)`).

`[1,2,3,4].map { &1 + 5 }`

If you wanna answer this question please Login or Register