[macruby-changes] [4676] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:58:09 PDT 2010


Revision: 4676
          http://trac.macosforge.org/projects/ruby/changeset/4676
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:58:08 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
If a result object responds to #pretty_inspect, for instance if pp is loaded, then use that

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

Modified Paths:
--------------
    DietRB/trunk/Rakefile
    DietRB/trunk/lib/irb/ext/colorize.rb
    DietRB/trunk/lib/irb/formatter.rb
    DietRB/trunk/spec/formatter_spec.rb

Modified: DietRB/trunk/Rakefile
===================================================================
--- DietRB/trunk/Rakefile	2010-10-08 10:57:57 UTC (rev 4675)
+++ DietRB/trunk/Rakefile	2010-10-08 10:58:08 UTC (rev 4676)
@@ -13,7 +13,7 @@
 
 desc "Run dietrb with ruby19"
 task :run do
-  sh "ruby19 -Ilib ./bin/dietrb -r irb/ext/completion -r irb/ext/colorize"
+  sh "ruby19 -Ilib ./bin/dietrb -r irb/ext/completion -r irb/ext/colorize -r pp"
 end
 
 begin

Modified: DietRB/trunk/lib/irb/ext/colorize.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/colorize.rb	2010-10-08 10:57:57 UTC (rev 4675)
+++ DietRB/trunk/lib/irb/ext/colorize.rb	2010-10-08 10:58:08 UTC (rev 4676)
@@ -122,7 +122,7 @@
     end
     
     def result(object)
-      "#{result_prefix} #{colorize(object.inspect)}"
+      "#{result_prefix} #{colorize(inspect_object(object))}"
     end
   end
 end

Modified: DietRB/trunk/lib/irb/formatter.rb
===================================================================
--- DietRB/trunk/lib/irb/formatter.rb	2010-10-08 10:57:57 UTC (rev 4675)
+++ DietRB/trunk/lib/irb/formatter.rb	2010-10-08 10:58:08 UTC (rev 4676)
@@ -27,8 +27,12 @@
       end
     end
     
+    def inspect_object(object)
+      object.respond_to?(:pretty_inspect) ? object.pretty_inspect : object.inspect
+    end
+    
     def result(object)
-      "=> #{object.inspect}"
+      "=> #{inspect_object(object)}"
     end
     
     def syntax_error(line, message)

Modified: DietRB/trunk/spec/formatter_spec.rb
===================================================================
--- DietRB/trunk/spec/formatter_spec.rb	2010-10-08 10:57:57 UTC (rev 4675)
+++ DietRB/trunk/spec/formatter_spec.rb	2010-10-08 10:58:08 UTC (rev 4676)
@@ -54,6 +54,12 @@
     @formatter.result(:foo => :foo).should == "=> {:foo=>:foo}"
   end
   
+  it "prints the result with object#pretty_inspect, if it responds to it" do
+    object = Object.new
+    def object.pretty_inspect; "foo"; end
+    @formatter.result(object).should == "foo"
+  end
+  
   it "prints that a syntax error occurred on the last line and reset the buffer to the previous line" do
     @formatter.syntax_error(2, "syntax error, unexpected '}'").should ==
       "SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/abfab066/attachment-0001.html>


More information about the macruby-changes mailing list