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.
65 66 67 68 69 |
# File 'lib/byebug/frame.rb', line 65 def args return c_args unless _binding ruby_args end |
#c_frame? ⇒ Boolean
Checks whether the frame is a c-frame
144 145 146 |
# File 'lib/byebug/frame.rb', line 144 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
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/byebug/frame.rb', line 92 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
79 80 81 |
# File 'lib/byebug/frame.rb', line 79 def deco_block _method[/(?:block(?: \(\d+ levels\))?|rescue) in /] || '' end |
#deco_call ⇒ Object
Builds a formatted string containing information about current method call
109 110 111 |
# File 'lib/byebug/frame.rb', line 109 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’
75 76 77 |
# File 'lib/byebug/frame.rb', line 75 def deco_class Setting[:callstyle] == 'short' || _class.to_s.empty? ? '' : "#{_class}." end |
#deco_file ⇒ Object
Formatted filename in frame
116 117 118 |
# File 'lib/byebug/frame.rb', line 116 def deco_file Setting[:fullpath] ? File.(file) : shortpath(file) end |
#deco_method ⇒ Object
83 84 85 |
# File 'lib/byebug/frame.rb', line 83 def deco_method _method[/((?:block(?: \(\d+ levels\))?|rescue) in )?(.*)/] end |
#deco_pos ⇒ Object
Properly formatted frame number of frame
123 124 125 |
# File 'lib/byebug/frame.rb', line 123 def deco_pos format('%-2d', 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
Use ‘Binding#local_variables` directly once we drop 2.1 support since it’s a public method since ruby 2.2
Gets local variables for the frame.
53 54 55 56 57 58 59 60 |
# File 'lib/byebug/frame.rb', line 53 def locals return [] unless _binding _binding.eval('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
134 135 136 137 138 139 |
# File 'lib/byebug/frame.rb', line 134 def mark return '-->' if current? return ' ͱ--' if c_frame? ' ' end |
#to_hash ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/byebug/frame.rb', line 148 def to_hash { mark: mark, pos: deco_pos, call: deco_call, file: deco_file, line: line, full_path: File.(deco_file) } end |