[macruby-changes] [4602] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:47:04 PDT 2010


Revision: 4602
          http://trac.macosforge.org/projects/ruby/changeset/4602
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:47:03 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Return a prompt string describing the context as IRB does

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:46:54 UTC (rev 4601)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-08 10:47:03 UTC (rev 4602)
@@ -1,5 +1,7 @@
 module IRB
   class Context
+    PROMPT = "irb(%s):%03d:%d> "
+    
     attr_reader :object, :binding, :line, :source
     
     def initialize(object)
@@ -13,6 +15,10 @@
       eval(source.to_s, @binding)
     end
     
+    def prompt
+      PROMPT % [@object.inspect, @line, @source.level]
+    end
+    
     private
     
     def clear_buffer

Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb	2010-10-08 10:46:54 UTC (rev 4601)
+++ DietRB/trunk/spec/context_spec.rb	2010-10-08 10:47:03 UTC (rev 4602)
@@ -34,4 +34,18 @@
     def o.to_s; "self"; end
     @context.evaluate(o).should == main
   end
+  
+  it "returns a prompt string, displaying line number and code indentation level" do
+    @context.prompt.should == "irb(main):001:0> "
+    @context.instance_variable_set(:@line, 23)
+    @context.prompt.should == "irb(main):023:0> "
+    @context.source << "def foo"
+    @context.prompt.should == "irb(main):023:1> "
+  end
+  
+  it "describes the context's object in the prompt" do
+    @context.prompt.should == "irb(main):001:0> "
+    o = Object.new
+    IRB::Context.new(o).prompt.should == "irb(#{o.inspect}):001:0> "
+  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/569b8afb/attachment-0001.html>


More information about the macruby-changes mailing list