summaryrefslogtreecommitdiff
path: root/lib/irb/context.rb
diff options
context:
space:
mode:
authorkeiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-07 11:36:20 +0000
committerkeiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-07 11:36:20 +0000
commitc7fa0c727c8342717d2c75c1c5750a54df461eae (patch)
tree418093a0a9aedf90397204d97730cffb9b95df07 /lib/irb/context.rb
parent649237de8f9e1c784493f4a8f29178ac0e969237 (diff)
* bin/irb, lib/irb.rb lib/irb/*: irb-0.9.6, extend inspect-mode
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r--lib/irb/context.rb47
1 files changed, 43 insertions, 4 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index a3f5e5a79c..a2778f76ab 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -1,6 +1,6 @@
#
# irb/context.rb - irb context
-# $Release Version: 0.9.5$
+# $Release Version: 0.9.6$
# $Revision$
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
@@ -9,6 +9,7 @@
#
#
require "irb/workspace"
+require "irb/inspector"
module IRB
class Context
@@ -34,8 +35,8 @@ module IRB
@load_modules = IRB.conf[:LOAD_MODULES]
@use_readline = IRB.conf[:USE_READLINE]
- @inspect_mode = IRB.conf[:INSPECT_MODE]
+ self.inspect_mode = IRB.conf[:INSPECT_MODE]
self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
@@ -189,15 +190,49 @@ module IRB
end
def inspect_mode=(opt)
- if opt
+
+ if i = INSPECTORS[opt]
@inspect_mode = opt
+ @inspect_method = i
+ i.init
else
- @inspect_mode = !@inspect_mode
+ case opt
+ when nil
+ if INSPECTORS.keys_with_inspector(INSPECTORS[true]).include?(@inspect_mode)
+ self.inspect_mode = false
+ elsif INSPECTORS.keys_with_inspector(INSPECTORS[false]).include?(@inspect_mode)
+ self.inspect_mode = true
+ else
+ puts "Can't switch inspect mode."
+ return
+ end
+ when /^\s*\{.*\}\s*$/
+ begin
+ inspector = eval "proc#{opt}"
+ rescue Exception
+ puts "Can't switch inspect mode(#{opt})."
+ return
+ end
+ self.inspect_mode = inspector
+ when Proc
+ self.inspect_mode = IRB::Inspector(opt)
+ when Inspector
+ prefix = "usr%d"
+ i = 1
+ while INSPECTORS[format(prefix, i)]; i += 1; end
+ @inspect_mode = format(prefix, i)
+ @inspect_method = opt
+ INSPECTORS.def_inspector(format(prefix, i), @inspect_method)
+ else
+ puts "Can't switch inspect mode(#{opt})."
+ return
+ end
end
print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
@inspect_mode
end
+
def use_readline=(opt)
@use_readline = opt
print "use readline module\n" if @use_readline
@@ -220,6 +255,10 @@ module IRB
# @_ = @workspace.evaluate(line, irb_path, line_no)
end
+ def inspect_last_value
+ @inspect_method.inspect_value(@last_value)
+ end
+
alias __exit__ exit
def exit(ret = 0)
IRB.irb_exit(@irb, ret)