cli/ruby-debug/commands/variables.rb in ruby-debug-0.9.3 vs cli/ruby-debug/commands/variables.rb in ruby-debug-0.10.0
- old
+ new
@@ -1,42 +1,44 @@
module Debugger
module VarFunctions # :nodoc:
def var_list(ary, b = get_binding)
ary.sort!
for v in ary
- print " %s => %s\n", v, debug_eval(v, b).inspect
+ begin
+ s = debug_eval(v, b).inspect
+ rescue
+ begin
+ s = debug_eval(v, b).to_s
+ rescue
+ s = "*Error in evaluation*"
+ end
+ end
+ if s.size > self.class.settings[:width]
+ s[self.class.settings[:width]-3 .. -1] = "..."
+ end
+ print "%s = %s\n", v, s
end
end
-
- def var_locals(locals)
- locals.keys.sort.each do |name|
- print " %s => %s\n", name, locals[name]
- end
- end
-
- def var_consts(mod)
- constants = mod.constants
- constants.sort!
- for c in constants
- print " %s => %s\n", c, mod.const_get(c)
- end
- end
end
class VarConstantCommand < Command # :nodoc:
- include VarFunctions
-
def regexp
/^\s*v(?:ar)?\s+c(?:onst(?:ant)?)?\s+/
end
def execute
obj = debug_eval(@match.post_match)
unless obj.kind_of? Module
print "Should be Class/Module: %s\n", @match.post_match
else
- var_consts(obj)
+ constants = debug_eval("#{@match.post_match}.constants")
+ constants.sort!
+ for c in constants
+ next if c =~ /SCRIPT/
+ value = obj.const_get(c) rescue "ERROR: #{$!}"
+ print " %s => %p\n", c, value
+ end
end
end
class << self
def help_command
@@ -50,12 +52,10 @@
end
end
end
class VarGlobalCommand < Command # :nodoc:
- include VarFunctions
-
def regexp
/^\s*v(?:ar)?\s+g(?:lobal)?\s*$/
end
def execute
@@ -74,18 +74,16 @@
end
end
end
class VarInstanceCommand < Command # :nodoc:
- include VarFunctions
-
def regexp
- /^\s*v(?:ar)?\s+i(?:nstance)?\s+/
+ /^\s*v(?:ar)?\s+i(?:nstance)?\s*/
end
def execute
- obj = debug_eval(@match.post_match)
+ obj = debug_eval(@match.post_match.empty? ? 'self' : @match.post_match)
var_list(obj.instance_variables, obj.instance_eval{binding()})
end
class << self
def help_command
@@ -99,17 +97,19 @@
end
end
end
class VarLocalCommand < Command # :nodoc:
- include VarFunctions
-
def regexp
/^\s*v(?:ar)?\s+l(?:ocal)?\s*$/
end
def execute
- var_locals(@state.context.frame_locals(@state.frame_pos))
+ locals = @state.context.frame_locals(@state.frame_pos)
+ _self = @state.context.frame_self(@state.frame_pos)
+ locals.keys.sort.each do |name|
+ print " %s => %p\n", name, locals[name]
+ end
end
class << self
def help_command
'var'