[macruby-changes] [4668] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:56:49 PDT 2010
Revision: 4668
http://trac.macosforge.org/projects/ruby/changeset/4668
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:56:48 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Clear the history and history file with Kernel#clear_history!
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/ext/history.rb
DietRB/trunk/spec/history_spec.rb
Modified: DietRB/trunk/lib/irb/ext/history.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/history.rb 2010-10-08 10:56:38 UTC (rev 4667)
+++ DietRB/trunk/lib/irb/ext/history.rb 2010-10-08 10:56:48 UTC (rev 4668)
@@ -27,6 +27,11 @@
File.read(self.class.file).split("\n")
end
+ def clear!
+ File.open(self.class.file, "w") { |f| f << "" }
+ Readline::HISTORY.clear
+ end
+
def history(number_of_entries = max_entries_in_overview)
history_size = Readline::HISTORY.size
start_index = 0
@@ -79,6 +84,10 @@
IRB::History.current.history!(entry_or_range)
end
alias_method :h!, :history!
+
+ def clear_history!
+ IRB::History.current.clear!
+ end
end
IRB::Context.processors << IRB::History
Modified: DietRB/trunk/spec/history_spec.rb
===================================================================
--- DietRB/trunk/spec/history_spec.rb 2010-10-08 10:56:38 UTC (rev 4667)
+++ DietRB/trunk/spec/history_spec.rb 2010-10-08 10:56:48 UTC (rev 4668)
@@ -45,6 +45,15 @@
Readline::HISTORY.to_a.should == ["puts :ok", "foo(x)"]
end
+
+ it "clears the history and history file" do
+ @history.input "puts :ok"
+ @history.input "foo(x)"
+ @history.clear!
+
+ @file.rewind; @file.read.should.be.empty
+ Readline::HISTORY.to_a.should.be.empty
+ end
end
class IRB::History
@@ -59,6 +68,13 @@
def puts(s)
printed << "#{s}\n"
end
+
+ def clear!
+ @cleared = true
+ end
+ def cleared?
+ @cleared
+ end
end
describe "IRB::History, concerning the user api" do
@@ -146,4 +162,9 @@
history! 2..6
@context.__evaluate__("AAA.new.bar").should == :ok
end
+
+ it "clears the history and history file" do
+ clear_history!
+ @history.should.be.cleared
+ end
end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/212b009b/attachment.html>
More information about the macruby-changes
mailing list