[macruby-changes] [4710] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 04:03:02 PDT 2010
Revision: 4710
http://trac.macosforge.org/projects/ruby/changeset/4710
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 04:03:00 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Add IRB::Formatter#inspect accessor to be able to disable inspect mode
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/formatter.rb
DietRB/trunk/spec/formatter_spec.rb
Modified: DietRB/trunk/lib/irb/formatter.rb
===================================================================
--- DietRB/trunk/lib/irb/formatter.rb 2010-10-08 11:02:51 UTC (rev 4709)
+++ DietRB/trunk/lib/irb/formatter.rb 2010-10-08 11:03:00 UTC (rev 4710)
@@ -17,11 +17,13 @@
SYNTAX_ERROR = "SyntaxError: compile error\n(irb):%d: %s"
SOURCE_ROOT = /^#{File.expand_path('../../../', __FILE__)}/
- attr_writer :prompt
- attr_reader :filter_from_backtrace
+ attr_writer :prompt
+ attr_accessor :inspect
+ attr_reader :filter_from_backtrace
def initialize
- @prompt = :default
+ @prompt = :default
+ @inspect = true
@filter_from_backtrace = [SOURCE_ROOT]
end
@@ -35,7 +37,13 @@
end
def inspect_object(object)
- object.respond_to?(:pretty_inspect) ? object.pretty_inspect : object.inspect
+ if @inspect
+ object.respond_to?(:pretty_inspect) ? object.pretty_inspect : object.inspect
+ else
+ address = object.__id__ * 2
+ address += 0x100000000 if address < 0
+ "#<#{object.class}:0x%x>" % address
+ end
end
def result(object)
Modified: DietRB/trunk/spec/formatter_spec.rb
===================================================================
--- DietRB/trunk/spec/formatter_spec.rb 2010-10-08 11:02:51 UTC (rev 4709)
+++ DietRB/trunk/spec/formatter_spec.rb 2010-10-08 11:03:00 UTC (rev 4710)
@@ -60,6 +60,17 @@
@formatter.result(object).should == "=> foo"
end
+ it "prints only the class name and memory address in `no inspect' mode" do
+ @formatter.inspect = false
+
+ object = Object.new
+ def object.inspect; @inspected = true; "Never called!"; end
+ def object.__id__; 2158110700; end
+
+ @formatter.result(object).should == "=> #<Object:0x101444fd8>"
+ object.instance_variable_get(:@inspected).should.not == true
+ 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/30fcc9ec/attachment-0001.html>
More information about the macruby-changes
mailing list