From: eden li Date: 2007-05-14T01:09:12+09:00 Subject: Re: Tiny IRB improvement - max-size of return format Nice patch. Not to steal your thunder, but you can also mute irb's response by tacking on "; nil" to the end of a particularly noisy return result: >> a = IO.read('somebigfile'); nil => nil >> a.scan(/blah/) => ... On May 13, 10:58 pm, Stian Haklev wrote: > I'm not sure if it's appropriate to post here, but I found this very > useful, wanted to share it with people, and didn't know where else. > > So I use IRB (and script/console) a lot for testing out regexps or small > code blocks, inspecting running Rails apps, and so on. One thing that > can be very annoying is when you run a command like > > IRB> a = File.read("bigfile.txt") > > and IRB spits out the entire contents of the file. The same happens when > you do > > user = User.find_by_name("Stian") > > in script/console, and the whole user object is inspected, often with > his/her files, messages, permissions etc added in > > As far as I know, there is only a way of turning this return off, but > not of limiting it. I tried turning it off, but found myself doing > > IRB> MD5::md5("Peter") > IRB> > > over and over, which was annoying. So I wrote this little patch: > > diff -r ../1.8-stian/irb/context.rb ./irb/context.rb > 37,38d36 > < @max_output_size = (IRB.conf[:MAX_OUTPUT_SIZE] ? > IRB.conf[:MAX_OUTPUT_SIZE] : 500) > < > 119d116 > < attr_accessor :max_output_size > diff -r ../1.8-stian/irb.rb ./irb.rb > 297c297 > < text = sprintf @context.return_format, > @context.last_value.inspect > ---> printf @context.return_format, @context.last_value.inspect > > 299c299 > < text = sprintf @context.return_format, @context.last_value > ---> printf @context.return_format, @context.last_value > > 301d300 > < puts text[0...@context.max_output_size] > > -- > > works on both Ruby 1.8.4 and 1.8.6. Basically it adds a new conf. option > - max_output_size, which defaults to 500, and restricts all results > based on this. Note that you can still see the whole thing by p object, > etc. > > I just wanted to share it, because I found it very useful. And it's neat > to be able to hack on "Ruby" itself, even in a tiny way :) > > thanks > Stian > > -- > Posted viahttp://www.ruby-forum.com/.