Issue #15724 has been updated by onlynone (Steven Willis).


alanwu (Alan Wu) wrote:
> You can type `a = 1; nil` to stop irb from calling inspect on the assignment expression result, just FYI.

Yes, this feature is so that one doesn't have to remember to do that after each expression they wouldn't normally want echo'd.

----------------------------------------
Feature #15724: Optionally suppress output from IRB for assignment expressions
https://bugs.ruby-lang.org/issues/15724#change-77281

* 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>