[#92063] [Ruby trunk Misc#15723] Reconsider numbered parameters — zverok.offline@...
Issue #15723 has been updated by zverok (Victor Shepelev).
3 messages
2019/03/31
[ruby-core:91950] [Ruby trunk Feature#15724] Optionally suppress output from IRB for assignment expressions
From:
onlynone@...
Date:
2019-03-22 21:18:31 UTC
List:
ruby-core #91950
Issue #15724 has been updated by onlynone (Steven Willis).
shevegen (Robert A. Heiler) wrote:
> I don't know if the original suggestion is good as is, but I think it is an interesting idea to support
> (unless there is already some config option for irb that does this, but I am not aware of it).
The only option is `@context.echo` which turns all echo-ing on or off.
> I don't think an external dependency can be merged, though.
Yes. As mentioned, that version with the `parser` gem was just my first-pass proof-of-concept to show what could be done. The first link I gave (https://github.com/ruby/irb/pull/12) has no external dependencies, but it's only available for >= 2.6.0.
> Perhaps
> there is another way to find out whether something is an assignment expression - that could actually
> be helpful in general.
That's exactly what I'm hoping the PR and this feature suggestion would help me find out.
----------------------------------------
Feature #15724: Optionally suppress output from IRB for assignment expressions
https://bugs.ruby-lang.org/issues/15724#change-77282
* Author: onlynone (Steven Willis)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Most REPLs I've used don't print out the output of assignment expressions like `a = 1`. Being able to suppress this output is very useful when you have a string which is essentially a blob, an object with a large string representation, or even an array of several objects like this. This happens to me often with rails' ActiveRecords where a query might return hundreds of objects that I just want to assign to a variable and don't want to inspect yet. It's even worse with rails because queries are run lazily, just because I did `a = User.where(name='Sally')` doesn't mean I actually wanted to execute that query against the db yet. I might want to do `a = a.where('age > 35')`. But irb doing the echo forces the evaluation.
I wrote this patch to irb: https://github.com/ruby/irb/pull/12 which would suppress irb's echo for assignment expressions when a new config setting: `context.echo_on_assignment` is false. It uses the new `RubyVM::AbstractSyntaxTree` to determine whether an expression is an assignment expression, so it only works on ruby >= 2.6.0. I'd very much welcome some feedback and any ideas on how to get it to work for earlier ruby versions.
I had also written a first-pass proof-of-concept that used the `parser` gem and would work for ruby >= 2.0.0 (https://github.com/ruby/irb/pull/11). This version obviously can't be merged because of the external dependency, but perhaps it can be treated like readline: use it if it's already installed, but don't depend on it?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>