[macruby-changes] [4723] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 04:05:02 PDT 2010


Revision: 4723
          http://trac.macosforge.org/projects/ruby/changeset/4723
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 04:05:01 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Use the IRB.io object by default and make a spec green

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/lib/irb/context.rb
    DietRB/trunk/lib/irb.rb
    DietRB/trunk/spec/context_spec.rb

Added Paths:
-----------
    DietRB/trunk/lib/irb/io.rb

Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb	2010-10-08 11:04:50 UTC (rev 4722)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-08 11:05:01 UTC (rev 4723)
@@ -5,7 +5,6 @@
 # Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
 
 require 'irb/formatter'
-require 'irb/io/readline'
 
 module IRB
   class Context
@@ -27,7 +26,7 @@
     end
     
     attr_reader :object, :binding, :line, :source, :processors
-    attr_accessor :io
+    attr_accessor :io, :formatter
     
     def initialize(object, explicit_binding = nil)
       @object  = object
@@ -35,8 +34,6 @@
       @line    = 1
       clear_buffer
       
-      @io = IRB::IO::Readline.new
-      
       @underscore_assigner = __evaluate__("_ = nil; proc { |val| _ = val }")
       @processors = self.class.processors.map { |processor| processor.new(self) }
     end
@@ -48,19 +45,19 @@
     def evaluate(source)
       result = __evaluate__(source.to_s, '(irb)', @line - @source.buffer.size + 1)
       store_result(result)
-      @io.puts(formatter.result(result))
+      io.puts(formatter.result(result))
       result
     rescue Exception => e
       store_exception(e)
-      @io.puts(formatter.exception(e))
+      io.puts(formatter.exception(e))
     end
     
-    # Prints the prompt to, and reads input from, the + at io+ object and passes
+    # Prints the prompt to, and reads input from, the +io+ object and passes
     # it to all processors.
     #
     # The buffer is cleared if an Interrupt exception is raised.
     def readline_from_io
-      input = @io.readline(formatter.prompt(self))
+      input = io.readline(formatter.prompt(self))
       @processors.each { |processor| input = processor.input(input) }
       input
     rescue Interrupt
@@ -94,7 +91,7 @@
       return false if @source.terminate?
       
       if @source.syntax_error?
-        @io.puts(formatter.syntax_error(@line, @source.syntax_error))
+        io.puts(formatter.syntax_error(@line, @source.syntax_error))
         @source.pop
       elsif @source.code_block?
         evaluate(@source)
@@ -106,14 +103,18 @@
     end
     
     def input_line(line)
-      @io.puts(formatter.prompt(self) + line)
+      io.puts(formatter.prompt(self) + line)
       process_line(line)
     end
     
     def formatter
-      IRB.formatter
+      @formatter ||= IRB.formatter
     end
     
+    def io
+      @io ||= IRB.io
+    end
+    
     def clear_buffer
       @source = Source.new
     end

Added: DietRB/trunk/lib/irb/io.rb
===================================================================
--- DietRB/trunk/lib/irb/io.rb	                        (rev 0)
+++ DietRB/trunk/lib/irb/io.rb	2010-10-08 11:05:01 UTC (rev 4723)
@@ -0,0 +1,12 @@
+# for now use Readline by default
+require 'irb/io/readline'
+
+module IRB
+  class << self
+    attr_writer :io
+    
+    def io
+      @io ||= IRB::IO::Readline.new
+    end
+  end
+end
\ No newline at end of file

Modified: DietRB/trunk/lib/irb.rb
===================================================================
--- DietRB/trunk/lib/irb.rb	2010-10-08 11:04:50 UTC (rev 4722)
+++ DietRB/trunk/lib/irb.rb	2010-10-08 11:05:01 UTC (rev 4723)
@@ -5,6 +5,7 @@
 # Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
 
 require 'irb/context'
+require 'irb/io'
 require 'irb/source'
 require 'irb/version'
 

Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb	2010-10-08 11:04:50 UTC (rev 4722)
+++ DietRB/trunk/spec/context_spec.rb	2010-10-08 11:05:01 UTC (rev 4723)
@@ -212,11 +212,12 @@
   end
 end
 
-# describe "Kernel::irb" do
-#   it "creates a new context for the given object and runs it" do
-#     Readline.stub_input("::IRBRan = self")
-#     o = Object.new
-#     irb(o)
-#     IRBRan.should == o
-#   end
-# end
+describe "Kernel::irb" do
+  it "creates a new context for the given object and runs it" do
+    IRB.io = CaptureIO.new
+    IRB.io.stub_input("::IRBRan = self")
+    o = Object.new
+    irb(o)
+    IRBRan.should == o
+  end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/fc59b6b7/attachment.html>


More information about the macruby-changes mailing list