[macruby-changes] [4609] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:48:08 PDT 2010
Revision: 4609
http://trac.macosforge.org/projects/ruby/changeset/4609
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:48:06 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Exit the runloop if the user wishes so.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/spec/context_spec.rb
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 10:47:57 UTC (rev 4608)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 10:48:06 UTC (rev 4609)
@@ -25,17 +25,34 @@
def run
while line = readline
- process_line(line)
+ continue = process_line(line)
+ break unless continue
end
end
+ # Returns whether or not the user wants to continue the current runloop.
+ # This can only be done at a code block indentation level of 0.
+ #
+ # For instance, this will continue:
+ #
+ # process_line("def foo") # => true
+ # process_line("quit") # => true
+ # process_line("end") # => true
+ #
+ # But at code block indentation level 0, `quit' means exit the runloop:
+ #
+ # process_line("quit") # => false
def process_line(line)
@source << line
+ return false if @source.to_s == "quit"
+
if @source.valid?
evaluate(@source)
clear_buffer
end
@line += 1
+
+ true
end
PROMPT = "irb(%s):%03d:%d> "
Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb 2010-10-08 10:47:57 UTC (rev 4608)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-08 10:48:06 UTC (rev 4609)
@@ -115,7 +115,7 @@
it "processes the output" do
Readline.stub_input("def foo")
- def @context.process_line(line); @received = line; end
+ def @context.process_line(line); @received = line; false; end
@context.run
@context.instance_variable_get(:@received).should == "def foo"
end
@@ -144,4 +144,19 @@
source = @context.instance_variable_get(:@evaled)
source.to_s.should == "def foo\n:ok\nend; p foo"
end
+
+ it "returns whether or not the runloop should continue, but only if the level is 0" do
+ @context.process_line("def foo").should == true
+ @context.process_line("quit").should == true
+ @context.process_line("end").should == true
+
+ @context.process_line("quit").should == false
+ end
+
+ it "exits the runloop if the user wishes so" do
+ Readline.stub_input("quit", "def foo")
+ def @context.process_line(line); @received = line; super; end
+ @context.run
+ @context.instance_variable_get(:@received).should.not == "def foo"
+ 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/617ead30/attachment.html>
More information about the macruby-changes
mailing list