Project

General

Profile

Actions

Feature #15724

open

Optionally suppress output from IRB for assignment expressions

Added by onlynone (Steven Willis) over 5 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:91937]

Description

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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0