Re:Ruby adds experimental support for rightward assignments
by choward on Thursday September 10, 2020 @03:05PM
(#24435506)
Then maybe it should be a feature that only exists in the REPL like _.
Re:Ruby adds experimental support for rightward assignments
by ultrarunner on Thursday September 10, 2020 @03:40PM
(#24435774)
I've got "<up> <ctrl-a> q = " in muscle memory by now. I feel like I've got a hand tied behind my back when I'm in a place that doesn't support those keybindings, but I'm not sure finding rightward assigns peppered at the 128th stack depth is going to make me a happier developer.
Re:Ruby adds experimental support for rightward assignments
by mcphage on Thursday September 10, 2020 @02:55PM
(#24435396)
This is the exact reason I've wanted this, for a long time. I even asked Matz about it a conference once, probably 10-ish years ago.
Re:Ruby adds experimental support for rightward assignments
by stouset on Thursday September 10, 2020 @04:42PM
(#24436389)
This is a completely unnecessary feature. `_` is always assigned to the value of the previous expression.
>> 4 + 2
=> 6
>> _
=> 6
>> "abc" + "def"
=> "abcdef"
>> _
=> "abcdef
Adding this kind of syntax for something that's already trivial to do is honestly kind of distressing for me as a Ruby developer who's been around since early 1.8.I still strongly believe that the `key: value` hash syntax was a massive mistake. That's a lost battle, but this is getting ridiculous.
Re:Ruby adds experimental support for rightward assignments
by jordoh on Thursday September 10, 2020 @06:40PM
(#24437302)
`_` being assigned the result of the last statement evaluated is an IRB feature [1], not a ruby feature - hence the note that it is not a universal solution.
[1]: https://github.com/ruby/irb/blob/master/lib/irb/context.rb#L...
Re:Ruby adds experimental support for rightward assignments
by stouset on Thursday September 10, 2020 @08:26PM
(#24438019)
So?
Why does this need to be in the language when both major REPLs already support it? Why must this be yet another alternative way to accomplish the same thing as the way that’s existed since the first days of the language?
There is no argument in favor of this addition. It doesn’t allow anything new, it provides a pointless alternative to the current way of doing things, and the one situation where it’s useful—REPLs—there’s already a feature that renders it completely unnecessary.
Disclaimer: I'm not a core dev but saw a discussion amongst them about such use cases.