[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

[PATCH] Persistent IRB history

From: Thomas Uehlinger <uehli@...>
Date: 2004-02-06 18:15:37 UTC
List: ruby-core #2352
Hi all

I found persistent Readline history (i.e. saved to a hidden file in the users home directory) a pretty useful feature in other applicatons.
So here is a patch for IRB so the history gets automatically saved to ~/.irb_history and will be loaded next time IRB is used.

Comments?

-- Thomas Uehlinger

Attachments (1)

input-method.rb.patch (991 Bytes, text/x-diff)
--- input-method_old.rb	2004-02-06 19:06:58.920287816 +0100
+++ input-method.rb	2004-02-06 19:04:50.228851888 +0100
@@ -85,12 +85,33 @@
     require "readline"
     class ReadlineInputMethod < InputMethod
       include Readline 
+      
+      def ReadlineInputMethod.create_finalizer(hist)
+        proc {|id|
+            open(File.join(ENV["HOME"], '.irb_history'), 'w' ) {|f|
+                i = 0
+                while (l = hist.pop and i < 50)
+                    f.puts(l)
+                    i += 1
+                end
+            }
+        }
+      end
+      
       def initialize
 	super
 
 	@line_no = 0
 	@line = []
 	@eof = false
+        
+        begin
+            lines = File.readlines(File.join(ENV["HOME"], '.irb_history'))
+            lines.reverse.each {|l| HISTORY.push << l.chomp }
+            HISTORY.pop
+        rescue
+        end
+        ObjectSpace.define_finalizer(self, ReadlineInputMethod.create_finalizer(HISTORY))
       end
 
       def gets

In This Thread

Prev Next