[macruby-changes] [4730] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 04:06:19 PDT 2010


Revision: 4730
          http://trac.macosforge.org/projects/ruby/changeset/4730
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 04:06:17 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Move running a file to a driver

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

Modified Paths:
--------------
    DietRB/trunk/bin/dietrb
    DietRB/trunk/lib/irb/context.rb

Added Paths:
-----------
    DietRB/trunk/lib/irb/driver/file.rb

Modified: DietRB/trunk/bin/dietrb
===================================================================
--- DietRB/trunk/bin/dietrb	2010-10-08 11:06:07 UTC (rev 4729)
+++ DietRB/trunk/bin/dietrb	2010-10-08 11:06:17 UTC (rev 4730)
@@ -33,13 +33,13 @@
 
 if ARGV.empty?
   require 'irb/driver/readline'
-  irb(self, TOPLEVEL_BINDING.dup)
-  # TODO make sure!
-  puts "ENDED! and this message should show up on stdout"
 else
   path = ARGV.shift
-  context = IRB::Context.new(self, TOPLEVEL_BINDING.dup)
-  File.open(path, 'r') do |file|
-    file.each_line { |line| context.input_line(line) }
-  end
-end
\ No newline at end of file
+  require 'irb/driver/file'
+  IRB.driver = IRB::Driver::File.new(path)
+end
+
+irb(self, TOPLEVEL_BINDING.dup)
+
+# TODO make sure!
+puts "ENDED! and this message should show up on stdout"
\ No newline at end of file

Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb	2010-10-08 11:06:07 UTC (rev 4729)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-08 11:06:17 UTC (rev 4730)
@@ -34,11 +34,11 @@
     def evaluate(source)
       result = __evaluate__(source.to_s, '(irb)', @line - @source.buffer.size + 1)
       store_result(result)
-      @driver.puts(formatter.result(result))
+      output.puts(formatter.result(result))
       result
     rescue Exception => e
       store_exception(e)
-      @driver.puts(formatter.exception(e))
+      output.puts(formatter.exception(e))
     end
     
     # Returns whether or not the user wants to continue the current runloop.
@@ -61,7 +61,7 @@
       return false if @source.terminate?
       
       if @source.syntax_error?
-        @driver.puts(formatter.syntax_error(@line, @source.syntax_error))
+        output.puts(formatter.syntax_error(@line, @source.syntax_error))
         @source.pop
       elsif @source.code_block?
         evaluate(@source)
@@ -77,10 +77,14 @@
     end
     
     def input_line(line)
-      @driver.puts(formatter.prompt(self) + line)
+      output.puts(formatter.prompt(self) + line)
       process_line(line)
     end
     
+    def output
+      @driver || $stdout
+    end
+    
     def formatter
       @formatter ||= IRB.formatter
     end

Added: DietRB/trunk/lib/irb/driver/file.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/file.rb	                        (rev 0)
+++ DietRB/trunk/lib/irb/driver/file.rb	2010-10-08 11:06:17 UTC (rev 4730)
@@ -0,0 +1,17 @@
+require 'irb/driver/tty'
+
+module IRB
+  module Driver
+    class File
+      def initialize(path)
+        @path = path
+      end
+      
+      def run(context)
+        ::File.open(@path, 'r') do |file|
+          file.each_line { |line| context.input_line(line) }
+        end
+      end
+    end
+  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/c1fda1ef/attachment-0001.html>


More information about the macruby-changes mailing list