Class: Byebug::Frame
- Inherits:
-
Object
- Object
- Byebug::Frame
- Includes:
- Helpers::FileHelper
- Defined in:
- lib/byebug/frame.rb
Overview
Represents a frame in the stack trace
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
- #_binding ⇒ Object
- #_class ⇒ Object
- #_method ⇒ Object
- #_self ⇒ Object
-
#args ⇒ Object
Gets current method arguments for the frame.
-
#c_frame? ⇒ Boolean
Checks whether the frame is a c-frame.
- #current? ⇒ Boolean
-
#deco_args ⇒ Object
Builds a string containing all available args in the frame number, in a verbose or non verbose way according to the value of the
callstyle
setting. - #deco_block ⇒ Object
-
#deco_call ⇒ Object
Builds a formatted string containing information about current method call.
-
#deco_class ⇒ Object
Returns the current class in the frame or an empty string if the current
callstyle
setting is ‘short’. -
#deco_file ⇒ Object
Formatted filename in frame.
- #deco_method ⇒ Object
-
#deco_pos ⇒ Object
Properly formatted frame number of frame.
- #file ⇒ Object
-
#initialize(context, pos) ⇒ Frame
constructor
A new instance of Frame.
- #line ⇒ Object
-
#locals ⇒ Object
Gets local variables for the frame.
-
#mark ⇒ Object
Formatted mark for the frame.
- #to_hash ⇒ Object
Methods included from Helpers::FileHelper
#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?
Constructor Details
#initialize(context, pos) ⇒ Frame
Returns a new instance of Frame.
14 15 16 17 |
# File 'lib/byebug/frame.rb', line 14 def initialize(context, pos) @context = context @pos = pos end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
12 13 14 |
# File 'lib/byebug/frame.rb', line 12 def pos @pos end |
Instance Method Details
#_binding ⇒ Object
31 32 33 |
# File 'lib/byebug/frame.rb', line 31 def _binding @context.frame_binding(pos) end |
#_class ⇒ Object
35 36 37 |
# File 'lib/byebug/frame.rb', line 35 def _class @context.frame_class(pos) end |
#_method ⇒ Object
39 40 41 |
# File 'lib/byebug/frame.rb', line 39 def _method @context.frame_method(pos) end |
#_self ⇒ Object
27 28 29 |
# File 'lib/byebug/frame.rb', line 27 def _self @context.frame_self(pos) end |
#args ⇒ Object
Gets current method arguments for the frame.
62 63 64 65 66 |
# File 'lib/byebug/frame.rb', line 62 def args return c_args unless _binding ruby_args end |
#c_frame? ⇒ Boolean
Checks whether the frame is a c-frame
141 142 143 |
# File 'lib/byebug/frame.rb', line 141 def c_frame? _binding.nil? end |
#current? ⇒ Boolean
43 44 45 |
# File 'lib/byebug/frame.rb', line 43 def current? @context.frame.pos == pos end |
#deco_args ⇒ Object
Builds a string containing all available args in the frame number, in a verbose or non verbose way according to the value of the callstyle
setting
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/byebug/frame.rb', line 89 def deco_args return "" if args.empty? my_args = args.map do |arg| prefix, default = prefix_and_default(arg[0]) kls = use_short_style?(arg) ? "" : "##{locals[arg[1]].class}" "#{prefix}#{arg[1] || default}#{kls}" end "(#{my_args.join(', ')})" end |
#deco_block ⇒ Object
76 77 78 |
# File 'lib/byebug/frame.rb', line 76 def deco_block _method[/(?:block(?: \(\d+ levels\))?|rescue) in /] || "" end |
#deco_call ⇒ Object
Builds a formatted string containing information about current method call
106 107 108 |
# File 'lib/byebug/frame.rb', line 106 def deco_call deco_block + deco_class + deco_method + deco_args end |
#deco_class ⇒ Object
Returns the current class in the frame or an empty string if the current callstyle
setting is ‘short’
72 73 74 |
# File 'lib/byebug/frame.rb', line 72 def deco_class Setting[:callstyle] == "short" || _class.to_s.empty? ? "" : "#{_class}." end |
#deco_file ⇒ Object
Formatted filename in frame
113 114 115 |
# File 'lib/byebug/frame.rb', line 113 def deco_file Setting[:fullpath] ? File.(file) : shortpath(file) end |
#deco_method ⇒ Object
80 81 82 |
# File 'lib/byebug/frame.rb', line 80 def deco_method _method[/((?:block(?: \(\d+ levels\))?|rescue) in )?(.*)/] end |
#deco_pos ⇒ Object
Properly formatted frame number of frame
120 121 122 |
# File 'lib/byebug/frame.rb', line 120 def deco_pos format("%-2<pos>d", pos: pos) end |
#file ⇒ Object
19 20 21 |
# File 'lib/byebug/frame.rb', line 19 def file @context.frame_file(pos) end |
#line ⇒ Object
23 24 25 |
# File 'lib/byebug/frame.rb', line 23 def line @context.frame_line(pos) end |
#locals ⇒ Object
Gets local variables for the frame.
50 51 52 53 54 55 56 57 |
# File 'lib/byebug/frame.rb', line 50 def locals return [] unless _binding _binding.local_variables.each_with_object({}) do |e, a| a[e] = _binding.local_variable_get(e) a end end |
#mark ⇒ Object
Formatted mark for the frame.
–> marks the current frame ͱ– marks c-frames
marks regular frames
131 132 133 134 135 136 |
# File 'lib/byebug/frame.rb', line 131 def mark return "-->" if current? return " ͱ--" if c_frame? " " end |
#to_hash ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/byebug/frame.rb', line 145 def to_hash { mark: mark, pos: deco_pos, call: deco_call, file: deco_file, line: line, full_path: File.(deco_file) } end |