On Thu, 2006-10-12 at 21:32 +0900, Dr Nic wrote:
> I recently discovered that I can create a .irbrc file to run setup for 
> my irb/console. I am in love.
> 
> ...
> 
> Does anyone any interesting things in their .irbrc file?

### I have these to help keep output manageable:

class Array
  alias :__orig_inspect :inspect

  def inspect
    (length > 20) ? "[ ... #{length} elements ... ]" : __orig_inspect
  end
end

class Hash
  alias :__orig_inspect :inspect

  def inspect
    (length > 20) ? "{ ... #{length} keys ... }" : __orig_inspect
  end
end

#### This for history (I believe I got it from Rubygarden):

HISTFILE = "~/.irb.hist"
MAXHISTSIZE = 100

begin
  if defined? Readline::HISTORY
    histfile = File::expand_path( HISTFILE )
    if File::exists?( histfile )
      lines = IO::readlines( histfile ).collect {|line| line.chomp}
      puts "Read %d saved history commands from %s." %
        [ lines.nitems, histfile ] if $DEBUG || $VERBOSE
      Readline::HISTORY.push( *lines )
    else
      puts "History file '%s' was empty or non-existant." %
        histfile if $DEBUG || $VERBOSE
    end

    Kernel::at_exit {
      lines = Readline::HISTORY.to_a.reverse.uniq.reverse
      lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems >
MAXHISTSIZE
      $stderr.puts "Saving %d history lines to %s." %

        [ lines.length, histfile ] if $VERBOSE || $DEBUG
      File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|
ofh|
        lines.each {|line| ofh.puts line }
      }
    }
  end
end

#### And this for RI (again, from Rubygarden or someone's blog, I forget
which):

def ri arg
   puts `ri #{arg}`
end

class Module
   def ri(meth=nil)
     if meth
       if instance_methods(false).include? meth.to_s
         puts `ri #{self}##{meth}`
       else
         super
       end
     else
       puts `ri #{self}`
     end
   end
end

-- 
Ross Bamford - rosco / roscopeco.REMOVE.co.uk