From: shevegen@... Date: 2019-03-22T17:05:06+00:00 Subject: [ruby-core:91943] [Ruby trunk Feature#15724] Optionally suppress output from IRB for assignment expressions Issue #15724 has been updated by shevegen (Robert A. Heiler). While I use a similar approach suggested by Alan Wu - and there is nothing wrong with that - I think it may still be useful to have a simpler toggle-way for silencing output by default (or, via a toggle). 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). I don't think an external dependency can be merged, though. For enabling additional functionality, as suggested by readline, I guess this has to be decided by the ruby core team whether that approach is good; the better approach would obviously be to have this a possibility for everyone. Perhaps there is another way to find out whether something is an assignment expression - that could actually be helpful in general. There are a few ruby projects that have to parse input and find out whether it is valid ruby syntax or not; and then also determine what this token is doing. I have had a similar need to do so in one project that aimed to write a shell-wrapper for ruby (and then re-use it in e. g. ruby bindings to vte, or just as a long loop {} to continually use readline to fetch input, and act on that input). So from this point of view I think this may be a useful suggestion. ---------------------------------------- Feature #15724: Optionally suppress output from IRB for assignment expressions https://bugs.ruby-lang.org/issues/15724#change-77275 * 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: